CSharp - Delegate Type Compatibility


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

The following two delegate are not in the same type.

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

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

You can cast one delegate type instance to another delegate type instance.

The following is permitted:

D2 d2 = new D2 (d1);

Delegate instances are equal if they are pointing th the same method:

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

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