X hits on this document

793 views

0 shares

0 downloads

0 comments

147 / 396

C# LANGUAGE SPECIFICATION

The new delegate instance is initialized with the same invocation list as the delegate instance given by E.

The invocation list of a delegate is determined when the delegate is instantiated and then remains constant for the entire lifetime of the delegate. In other words, it is not possible to change the target callable entities of a delegate once it has been created. When two delegates are combined or one is removed from another (§‎15.1), a new delegate results; no existing delegate has its contents changed.

It is not possible to create a delegate that refers to a property, indexer, user-defined operator, instance constructor, destructor, or static constructor.

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.

7.5.11 The typeof operator

The typeof operator is used to obtain the System.Type object for a type.

typeof-expression: typeof   (   type   ) typeof   (   void   )

The first form of typeof-expression consists of a typeof keyword followed by a parenthesized type. The result of an expression of this form is the System.Type object for the indicated type. There is only one System.Type object for any given type. This means that for type T, typeof(T) == typeof(T) is always true.

The second form of typeof-expression consists of a typeof keyword followed by a parenthesized void keyword. The result of an expression of this form is the System.Type object that represents the absence of a type. The type object returned by typeof(void) is distinct from the type object returned for any type. This special type object is useful in class libraries that allow reflection onto methods in the language, where those methods wish to have a way to represent the return type of any method, including void methods, with an instance of System.Type.

The example

using System;

134Copyright Microsoft Corporation 1999-2003. All Rights Reserved.

Document info
Document views793
Page views793
Page last viewedSat Dec 03 20:47:34 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments