You've seen this! Your customer will see too. Buy this place

The params keyword in C#

1 1 1 1 1 The params keyword in C#5.00Rating 5.00 (1 Vote)

Specifying the the C# params keyword as a function argument allows one to pass a variating number of arguments to the function. The type of the arguments should be specified preceding the params keyword. When calling the function, the arguments can be specified comma-delimited, or passwd in as a simple array. The arguments can be also omitted. When declaring a function, the params keyword should go last in the params list. No arguments are allowed after the params is specified. Also no two params are allowed in the declaration. Also notice the arguments can only be of same type only. You can specify generic object type, ut in this can you have to distinguish between arguments.

An example of using a method with the params keyword applied to the parameter:

static void ShowArray(string name, params int[] array)
{
Console.Write(name);
for (int i = 0; i< array.Length; i++)
{
Console.Write("{0} ", array[i]);
}
Console.WriteLine();
}
static void Main()
{
int[] arr = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
ShowArray("Numbers: ", arr);
Console.WriteLine();
ShowArray("Numbers: ", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
Console.ReadKey();
}

 

Wednesday the 23rd.