Jon Jagger
Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specificationpreviousnextprevious at this levelnext at this level 14 Expressionsprevious at this levelnext at this level 14.4 Function membersprevious at this levelnext at this level 14.4.1 Argument lists Paragraph 11 Every function member invocation includes an argument list, which provides actual values or variable references for the parameters of the function member. 2 The syntax for specifying the argument list of a function member invocation depends on the function member category: Paragraph 21 The arguments of properties (§17.6), events (§17.7), indexers (§17.8), and user-defined operators (§17.9) are always passed as value parameters (§ 2 Reference and output parameters are not supported for these categories of function members. Paragraph 31 The arguments of an instance constructor, method, or delegate invocation are specified as an argument-list: argument-list : argument argument-list , argument argument : expression ref variable-reference out variable-reference Paragraph 41 An argument-list consists of one or more arguments, separated by commas. 2 Each argument can take one of the following forms: Paragraph 51 During the run-time processing of a function member invocation (§14.4.3), the expressions or variable references of an argument list are evaluated in order, from left to right, as follows: Paragraph 61 Methods, indexers, and instance constructors may declare their right-most parameter to be a parameter array (§ 2 Such function members are invoked either in their normal form or in their expanded form depending on which is applicable (§ Paragraph 71 The expressions of an argument list are always evaluated in the order they are written. [Example: Thus, the example
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 = 2  
end 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 (§ 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.
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS