如何在where语句后添加泛型参数?
我有一个抽象类,如下所示:
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();
}
}
那么,如果为名为 T2 的通用添加额外参数,我该如何对此进行额外约束?
abstract class BaseClass<T, **T2**> where T : BaseReturnType ???
{
public abstract T PolymorphicMethod();
}
I have an abstract class as follow:
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();
}
}
So if add exta parrameter for Generic called T2 how do I put extrac constraining on this?
abstract class BaseClass<T, **T2**> where T : BaseReturnType ???
{
public abstract T PolymorphicMethod();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按照此处。
as per here.