Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I declare an abstract generic class that inherits from another abstract class?

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?

like image 399
Mike Avatar asked Dec 27 '10 20:12

Mike


2 Answers

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.

like image 140
bdukes Avatar answered Oct 23 '22 00:10

bdukes


You just put the base class in before the template constraint.

public abstract class Class1<T> : Class2 where T : SomeBaseClass, new()
like image 24
Ray Hidayat Avatar answered Oct 23 '22 00:10

Ray Hidayat