By using the params
keyword, you can specify a method parameter that takes a variable number of arguments.
You can send a comma-separated list of arguments of the type specified in the parameter declaration or an array of arguments of the specified type. You also can send no arguments. If you send no arguments, the length of the params
list is zero.
No additional parameters are permitted after the params
keyword in a method declaration, and only one params
keyword is permitted in a method declaration.
void PrintReport(string header, params int[] numbers) { Console.WriteLine(header); foreach (int number in numbers) Console.WriteLine(number); }