We cannot instantiate Delegate
and MulticastDelegate
classes as these classes are abstract
:
public abstract class Delegate : ICloneable, ISerializable { ... }
public abstract class MulticastDelegate : Delegate { ... }
The primary way to work with delegates is delegate
keyword. The C# compiler creates instances of a class derived from MulticastDelegate
when we use the C# language keyword delegate
to declare delegate types.
The reason of why C# compiler creates instances of a class derived from MulticastDelegate is:
This design has its roots in the first release of C# and .NET. One
goal for the design team was to ensure that the language enforced type
safety when using delegates. That meant ensuring that delegates were
invoked with the right type and number of arguments. And, that any
return type was correctly indicated at compile time. Delegates were
part of the 1.0 .NET release, which was before generics.
The best way to enforce this type safety was for the compiler to
create the concrete delegate classes that represented the method
signature being used.
Even though you cannot create derived classes directly, you will use
the methods defined on these classes.
It can be seen that delegates were part of the 1.0 .NET release, which was before generics, so it can be concluded that constraint where T : System.Delegate { }
exists in C# 7.3 by historical reason to enforce the type safety for the compiler by creating the concrete delegate classes that represented the method signature being used.