0
假設我有一個接口IA,其中包含一個名爲Foo的泛型方法。C# - 匹配派生類型的接口通用方法約束
public interface IA {
int Foo<T>(T otherType);
}
我想噸至是同一類型的派生類:
class A : IA {
int Foo(A otherType)
{
}
}
我嘗試以下(語法錯誤):
public interface IA {
int Foo<T>(T otherType) where T : this;
}
如何我約束需要看起來像實現這一目標?
不要以爲這是可能的。界面不知道將實施它。這基本上是雞/蛋的東西。 – Jamiec