class Test { static void F(int x, int y, int z) { System.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 = 2end example] Paragraph 81 The array covariance rules (§19.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. 2 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. [Example: 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 a System.ArrayTypeMismatchException to be thrown because the actual element type of b is string and not object. end example] Paragraph 91 When a function member with a parameter array is invoked in its expanded form, the invocation is processed exactly as if an array creation expression with an array initializer (§14.5.10.2) was inserted around the expanded parameters. [Example: For example, given the declaration
void F(int x, int y, params object[] args);the following invocations of the expanded form of the method
F(10, 20); F(10, 20, 30, 40); F(10, 20, 1, "hello", 3.0);correspond exactly to
F(10, 20, new object[] {}); F(10, 20, new object[] {30, 40}); F(10, 20, new object[] {1, "hello", 3.0});end example] 2 In particular, note that an empty array is created when there are zero arguments given for the parameter array.
| |
Jagger Software Ltd | |
Company # 4070126 | |
VAT # 762 5213 42 |