更新:2007 年 11 月
错误消息
不能将类型“type1”用作泛型类型或方法“name”中的类型参数“name”。没有从“type1”到“type2”的装箱转换或类型参数转换。
在泛型类型使用具有约束的类型参数时,新的类也必须满足这些相同的约束。
更正此错误
- 在下面的示例中,将 where T : ClassConstraint 添加到类 B。
示例
下面的代码生成 CS0314:
// cs0314.cs
// Compile with: /target:library
public class ClassConstraint { }
public class A<T> where T : ClassConstraint
{ }
public class B<T> : A<T> //CS0314
{ }
// Try using this instead.
public class C<T> : A<T> where T : ClassConstraint
{ }