17.5.1.4 Parameter arrays
A parameter array permits arguments to
be specified in one of two ways in a
method invocation:
• The argument
given for a parameter array can be a
single expression of a type that is
implicitly convertible (§13.1) to the
parameter array type. In this case,
the parameter array acts precisely
like a value parameter.
•
Alternatively, the invocation can
specify zero or more arguments for the
parameter array, where each argument
is an expression of a type that is
implicitly convertible (§13.1) to the
element type of the parameter array.
In this case, the invocation creates
an instance of the parameter array
type with a length corresponding to
the number of arguments, initializes
the elements of the array instance
with the given argument values, and
uses the newly created array instance
as the actual argument.
In the same section an example is given:
using System;
class Test
{
static void F(params int[] args) {
Console.Write("Array contains {0} elements:", args.Length);
foreach (int i in args)
Console.Write(" {0}", i);
Console.WriteLine();
}
static void Main() {
int[] arr = {1, 2, 3};
F(arr);
F(10, 20, 30, 40);
F();
}
}
produces the output
Array contains 3 elements: 1 2 3 Array
contains 4 elements: 10 20 30 40 Array
contains 0 elements:
This example illustrates the expected behavior: empty array