Jon Jagger
jon@jaggersoft.com
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.5 Primary expressionsprevious at this levelnext at this level 14.5.10 The new operatorprevious at this levelnext at this level 14.5.10.3 Delegate creation expressions Paragraph 11 A delegate-creation-expression is used to create a new instance of a delegate-type. delegate-creation-expression : new delegate-type ( expression ) Paragraph 21 The argument of a delegate creation expression must be a method group (§14.1) or a value of a delegate-type. 2 If the argument is a method group, it identifies the method and, for an instance method, the object for which to create a delegate. 3 If the argument is a value of a delegate-type, it identifies a delegate instance of which to create a copy. Paragraph 31 The compile-time processing of a delegate-creation-expression of the form new D(E), where D is a delegate-type and E is an expression, consists of the following steps: Paragraph 41 The run-time processing of a delegate-creation-expression of the form new D(E), where D is a delegate-type and E is an expression, consists of the following steps: Paragraph 51 The method and object to which a delegate refers are determined when the delegate is instantiated and then remain constant for the entire lifetime of the delegate. 2 In other words, it is not possible to change the target method or object of a delegate once it has been created. [Note: Remember, when two delegates are combined or one is removed from another, a new delegate results; no existing delegate has its content changed. end note] Paragraph 61 It is not possible to create a delegate that refers to a property, indexer, user-defined operator, instance constructor, destructor, or static constructor. [Example: As described above, when a delegate is created from a method group, the formal parameter list and return type of the delegate determine which of the overloaded methods to select. In the example
delegate double DoubleFunc(double x);  
class A  
{  
   DoubleFunc f = new DoubleFunc(Square);  
   static float Square(float x) {  
      return x * x;  
   }  
   static double Square(double x) {  
      return x * x;  
   }  
}  
the A.f field is initialized with a delegate that refers to the second Square method because that method exactly matches the formal parameter list and return type of DoubleFunc. Had the second Square method not been present, a compile-time error would have occurred. end example]
{ JSL }
Jagger Software Ltd
Company # 4070126
VAT # 762 5213 42
Valid HTML 4.01Valid CSS