次のコードでは:
interface IMyInterface<X>
{
X Get();
}
class MyInterface : IMyInterface<int>
{
int Get();
}
class MyClass<T, U> where T : IMyInterface<U>
{
U Value;
}
U は常に T の関数になります。ただし、MyClass を使用するには、次のようにする必要があります。
MyClass<MyInterface, int> instance;
次のように入力できればいいのですが。
MyClass<MyInterface> instance;
そして、U が int であることを暗示するようにします。U をそのように指定する必要がないように、コードを再構築する方法はありますか?