The params parameter modifier can be added to the last parameter of a method.
Method with params parameter accepts any number of arguments of a particular type.
The parameter type must be declared as an array.
For example:
using System; class Test//from ww w . ja v a 2s . co m { static int Sum (params int[] ints) { int sum = 0; for (int i = 0; i < ints.Length; i++){ sum += ints[i]; } return sum; } static void Main() { int total = Sum (1, 2, 3, 4); Console.WriteLine (total); // 10 } }
You can use a params argument as an ordinary array.
int total = Sum (new int[] { 1, 2, 3, 4 } );