更新:2007 年 11 月

错误消息

“class”或“struct”约束必须在其他任何约束之前

对泛型类型或方法的类型参数的约束必须以某一指定的顺序发生:classstruct 必须是第一个(如果存在),然后是任何接口约束,最后是任何构造函数约束。此错误是由于 classstruct 约束没有先出现所致。要解决此错误,请重新排列约束子句。

示例

下面的示例生成 CS0449。

 复制代码
// CS0449.cs
// compile with: /target:library
interface I {}
public class C4 
{
   public void F1<T>() where T : class, struct, I {}   // CS0449
   public void F2<T>() where T : I, struct {}   // CS0449
   public void F3<T>() where T : I, class {}   // CS0449

   // OK
   public void F4<T>() where T : class {}
   public void F5<T>() where T : struct {}
   public void F6<T>() where T : I {}
}