How to declare an abstract generic class that inherits from another abstract class?

I'm at a dead end 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 it?

+4
source share
3 answers

The inherited class appears before the where clause.

 public abstract class Class1<T> : Class2 where T : SomeBaseClass, new() 

See also the MSDN page for Common Classes .

+10
source

You simply placed the base class before the template constraint.

 public abstract class Class1<T> : Class2 where T : SomeBaseClass, new() 
+1
source

Just put the inheritance clause before the generic type constraint. This will be more readable, IMO, if the restriction is on a separate line.

 public abstract class Class2 { } public abstract class Class1<T> : Class2 where T : SomeBaseClass, new() { } 
0
source

Source: https://habr.com/ru/post/1333501/


All Articles