Although delegate type and Enum type are class types, we can not inherit from them as they are sealed classes after compile,
public delegate void DelegateTestType();
//Compile time error
class myTest : DelegateTestType
{
...
}
we can not make it as a type constraint either on class or method:
//Compile time error
class myTest<T> where T : DelegateTestType
{
}
A class-type constraint must satisfy the following rules:
· The type must be a class type.
· The type must not be sealed.
· The type must not be one of the following types: System.Array, System.Delegate, System.Enum, or System.ValueType.
· The type must not be object. Because all types derive from object, such a constraint would have no effect if it were permitted.
· At most one constraint for a given type parameter can be a class type.
In c# world we have to use some indirect ways, like type casting, wrapper class or examine the type is Delegate type, it is still a problem in C# 4.0, this is a bit sad as C++ can do it more than happily!