Parameter Arrays in C#. In this article we will see how to use Parameter Arrays with an 

In normal function we can allow fixed number of function arguments like

Int Add(int x,int y )
{
      Return x+y;
}

But what if number of augments are not fixed we want that user allowed to pass as much arguments he want to entered are allowed .In this case the parameter arrays comes in handy..

We can define param array in Function argument by keyword "params" followed by <type name> and then array name.

We will make a add function that will allow as many arguments as user wants to input in function 


01class Program
02{
03        static int Add(params int[] nums)
04        {
05            int total=0;
06            foreach(int in nums)
07            {
08                total = total+i;
09            }
10            return total;
11        }
12 
13        static void Main(string[] args)
14        {
15            Console.WriteLine("Parameter Array Function Testing ...");
16 
17            int result=0;
18 
19            /* function allowing 3 arguments */
20            result = Add(10, 10, 10);
21            Console.WriteLine("Result for 3 Prameter :{0}", result);
22 
23            /* function allowing 4 arguments */
24            result = Add(10, 10, 10, 10);
25 
26            Console.WriteLine("Result for 4 Prameter :{0}", result);
27 
28            /* function allowing 5 arguments */
29            result = Add(10, 10, 10, 10,10);
30 
31            Console.WriteLine("Result for 5 Prameter :{0}", result);
32 
33 
34            /* function is also allowing whole array too */
35            int[] x = { 10, 10, 10, 10, 10, 10, 10, 10 };
36 
37            Console.ForegroundColor = ConsoleColor.Red;
38            result = Add(x);
39            Console.WriteLine("Result for Array Summation Prameter :{0}", result);
40 
41            Console.ReadKey();
42}