Function with variable number of arguments

Yes you can write something like this:

void PrintReport(string header, params int[] numbers)
{
    Console.WriteLine(header);
    foreach (int number in numbers)
        Console.WriteLine(number);
}

Try using the params keyword, placed before the statement, eg

myFunction(params int[] numbers);

Yes, there is. As Adriano said you can use C# 'params' keyword. An example is the in link below:

params (C# Reference)

http://msdn.microsoft.com/en-us/library/w5zay9db.aspx

"The params keyword lets you 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.

No additional parameters are permitted after the params keyword in a method declaration, and only one params keyword is permitted in a method declaration."


You can declare a method to har a variable number of parameters by using the params keyword. Just like when using ... in Java, this will give you an array and let you call the metods with a variable number of parameters: http://msdn.microsoft.com/en-us/library/w5zay9db(v=vs.71).aspx


This should be

void printReport(String header, params int[] numbers)