編譯器錯誤 CS0314
更新:2007 年 11 月
錯誤訊息
型別 'type1' 不能做為泛型型別或方法 'name' 中的型別參數 'name'。沒有從 'type1' 到 'type2' 的 Boxing 轉換或型別參數轉換。
泛型型別使用加上條件約束的型別參數時,新的類別 (Class) 也必須滿足那些相同條件約束 (Constraint)。
若要更正這個錯誤
- 在下列範例中,將 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
{ }