Every function member invocation includes an argument list which provides actual values or variable references for the parameters of the function member. The syntax for specifying the argument list of a function member invocation depends on the function member category:
get
accessor, and consists of the expression specified as the right operand of the assignment operator when invoking the set
accessor.set
accessor, the argument list additionally includes the expression specified as the right operand of the assignment operator.The arguments of properties, indexers, and user-defined operators are always passed as value parameters (§10.5.1.1). Reference and output parameters are not supported for these categories of function members.
The arguments of a constructor, method, or delegate invocation are specified as an argument-list:
An argument-list consists of zero or more arguments, separated by commas. Each argument can take one of the following forms:
ref
followed by a variable-reference (§5.4), indicating that the argument is passed as a reference parameter (§10.5.1.2). A variable must be definitely assigned (§5.3) before it can be passed as a reference parameter.out
followed by a variable-reference (§5.4), indicating that the argument is passed as an output parameter (§10.5.1.3). A variable is considered definitely assigned (§5.3) following a function member invocation in which the variable is passed as an output parameter.During the run-time processing of a function member invocation (§7.4.3), the expressions or variable references of an argument list are evaluated in order, from left to right, as follows:
ArrayTypeMismatchException
is thrown.The expressions of an argument list are always evaluated in the order they are written. Thus, the example
class Test { static void F(int x, int y, int z) { Console.WriteLine("x = {0}, y = {1}, z = {2}", x, y, z); } static void Main() { int i = 0; F(i++, i++, i++); } }
produces the output
x = 0, y = 1, z = 2
The array co-variance rules (§12.5) permit a value of an array type A[]
to be a reference to an instance of an array type B[]
, provided an implicit reference conversion exists from B
to A
. Because of these rules, when an array element of a reference-type is passed as a reference or output parameter, a run-time check is required to ensure that the actual element type of the array is identical to that of the parameter. In the example
class Test { static void F(ref object x) {...} static void Main() { object[] a = new object[10]; object[] b = new string[10]; F(ref a[0]); // Ok F(ref b[1]); // ArrayTypeMismatchException } }
the second invocation of F
causes an ArrayTypeMismatchException
to be thrown because the actual element type of b
is string
and not object
.