[英]Can you enforce the same constraint on multiple generic type parameters?
I know you can you can do it like this: 我知道您可以这样做:
void M<T1, T2, T3>() where T1 : S where T2 : S where T3 : S
{}
I want something like this: 我想要这样的东西:
void M<T1, T2, T3>() where T1, T2, T3 : S
{}
Is there any such shortcut? 有没有这样的捷径?
No, that is not supported. 不,不支持。 The C# language spec states C#语言规范指出
Each type-parameter-constraint-clause consists of the token where, followed by the name of a type parameter, followed by a colon and the list of constraints for that type parameter. 每个type-parameter-constraint-clause都由标记组成,其中标记,其后是类型参数的名称,然后是冒号和该类型参数的约束列表。
The key here is a , indicating that the grammer requires where <TypeParam> : <Constraint1>,<Constraint2>, etc..
. 这里的关键是 ,表示语法要求where <TypeParam> : <Constraint1>,<Constraint2>, etc..
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.