Reputation: 5529
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?
Upvotes: 5
Views: 2796
Reputation: 532665
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()
{
}
Upvotes: 0
Reputation: 16229
You just put the base class in before the template constraint.
public abstract class Class1<T> : Class2 where T : SomeBaseClass, new()
Upvotes: 1
Reputation: 156055
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.
Upvotes: 11