I'm stumped on this one right now.
What I have: public abstract class Class1<T> where T : SomeBaseClass, new()
I want Class1 to inherit from: public abstract class Class2
. How can I do this? Can I do this?
The inherited class comes before the where
clause .
public abstract class Class1<T> : Class2 where T : SomeBaseClass, new()
See also the MSDN page on Generic Classes .
您只需在模板约束之前放入基类。
public abstract class Class1<T> : Class2 where T : SomeBaseClass, new()
Just put the inheritance clause before the generic type constraint. It will be more readable, IMO, if the constraint is on a separate line.
public abstract class Class2
{
}
public abstract class Class1<T> : Class2
where T : SomeBaseClass, new()
{
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.