Params Array : params : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » params »

 

Params Array








    
 

using System;
using System.Collections.Generic;
using System.Text;

class Util {
    public static int Sum(params int[] paramList) {
        if (paramList == null) {
            throw new ArgumentException("Util.Sum: null parameter list");
        }

        if (paramList.Length == 0) {
            throw new ArgumentException("Util.Sum: empty parameter list");
        }

        int sumTotal = 0;
        foreach (int i in paramList) {
            sumTotal += i;
        }
        return sumTotal;
    }
}
class Program {
    static void Entrance() {
        Console.WriteLine(Util.Sum(10, 9, 8, 7, 6, 5, 4, 3, 2, 1));
    }

    static void Main() {
        try {
            Entrance();
        } catch (Exception ex) {
            Console.WriteLine("Exception: {0}", ex.Message);
        }
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» params