私はいくつかのインターフェースMyClass<T>
であるクラスを持っています:T
class MyClass<T> where T: IMyInterface
MyClass
の実装を使用して拡張するいくつかのクラスを作成IMyInterface
しました。たとえば、次のようになります。
class MySecondClass : MyClass<MyInterfaceImplementation>
MySecondClass
型を持つ変数への代入インスタンスがMyClass<IMyInterface>
許可されないのはなぜですか?
MyClass<IMyInterface> x = new MySecondClass()
暗黙の変換を追加すると:
public static implicit operator MyClass<IMyInterface>(MySecondClass c) {
return c;
}
それは働き始めます。