![](/img/trans.png)
[英]How to define a generic abstract class that inherits a generic abstract class?
[英]How can I declare an abstract generic class that inherits from another abstract class?
我现在对这个很难过。
我有什么: public abstract class Class1<T> where T : SomeBaseClass, new()
我希望Class1继承自: public abstract class Class2
。 我怎样才能做到这一点? 我可以这样做吗?
您只需在模板约束之前放入基类。
public abstract class Class1<T> : Class2 where T : SomeBaseClass, new()
只需将inheritance子句放在泛型类型约束之前。 如果约束在一个单独的行上,它将更具可读性IMO。
public abstract class Class2
{
}
public abstract class Class1<T> : Class2
where T : SomeBaseClass, new()
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.