We can restrict the type be the class or struct. Can we strict the type be a delegate?
A Delegate
is a class, and you would normally be able to specify a non-sealed class as a constraint. However, the language specification specifically excludes System.Delegate
as a valid constraint in section 10.1.5.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With