General method in abstract class

I have the following abstract base class in which I have an abstract method. I need to know how to implement this abstract method in child classes. The problem is how to declare a class whose base is SomeBaseClass in class B.

public abstract class A { protected abstract void Add<T>(T number) where T : SomeBaseClass; } public class B : A { protected override void Add<T>(T number) { throw new NotImplementedException(); } } 
+7
source share
1 answer

I think you want the base class to have a type parameter, not a concrete method:

 public abstract class A<T> where T : SomeBaseClass { protected abstract void Add(T number); } public class B : A<C> { protected void Add(C number) { ... } } 
+10
source

All Articles