Delegate Compatibility - CSharp Custom Type

CSharp examples for Custom Type:delegate

Type compatibility

Delegate types are all incompatible with one another, even if their signatures are the same:

delegate void D1();
delegate void D2();
...

D1 d1 = Method1;
D2 d2 = d1;                           // Compile-time error

The following, however, is permitted:

D2 d2 = new D2 (d1);

Delegate instances are considered equal if they have the same method targets:

delegate void D();
 ...

D d1 = Method1;
D d2 = Method1;
Console.WriteLine (d1 == d2);         // True

Multicast delegates are considered equal if they reference the same methods in the same order.


Related Tutorials