<分区>
我们可以将类型限制为类或结构。我们可以将类型限制为委托(delegate)吗?
<分区>
我们可以将类型限制为类或结构。我们可以将类型限制为委托(delegate)吗?
最佳答案
Delegate
是一个类,您通常可以指定一个非密封类作为约束。但是,语言规范明确将 System.Delegate
作为第 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.
关于c# - 我们可以将类型限制为委托(delegate)吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4161104/