コンパイラ エラー CS0314

型 'type1' をジェネリック型の型パラメーター 'name' またはメソッド 'name' として使用することはできません。 'type1' から 'type2' へのボックス化変換や型パラメーター変換はありません。

ジェネリック型で使用している型パラメーターに制約がある場合は、新しいクラスもその同じ制約を満たす必要があります。

このエラーを解決するには

  1. 次の例では、 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  
{ }  

関連項目