我有一个抽象类如下:
class BaseReturnType { }
class DerivedReturnType : BaseReturnType { }
abstract class BaseClass<T> where T : BaseReturnType
{
public abstract T PolymorphicMethod();
}
class DerivedClass : BaseClass<DerivedReturnType>
{
public override DerivedReturnType PolymorphicMethod()
{
return new DerivedReturnType();
}
}
因此,如果为Generic添加额外参数T2,我该如何对此进行extrac约束?
abstract class BaseClass<T, **T2**> where T : BaseReturnType ???
{
public abstract T PolymorphicMethod();
}
答案 0 :(得分:4)
abstract class BaseClass<T, **T2**> where T : BaseReturnType where T2 : BaseTypeForT2
{
public abstract T PolymorphicMethod();
}
根据here。