更新:2007 年 11 月
错误消息
类型参数“Type Parameter Name 1”具有“struct”约束,因此“Type Parameter Name 1”不能用作“Type Parameter Name 2”的约束值类型约束被隐式密封,因此那些约束不能用作另一个类型参数的约束。这是因为无法重写值类型。要解决此错误,请直接在第二个类型参数上设置值类型约束,而不是通过第一个类型参数间接这样做。
 示例
示例
下面的示例生成 CS0456。
|  复制代码 | |
|---|---|
| // CS0456.cs
// compile with: /target:library
public class GenericsErrors
{
   public class G5<T> where T : struct
   {
      public class N<U> where U : T {}   // CS0456
      public class N2<U> where U : struct {}   // OK
   }
} | |
 
     
     
     
    