KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have the following structure: abstract class Base { public abstract List<...> Get(); //What should be the generic type? } class SubOne : Base { public override List<SubOne> Get() { } } class SubTwo : Base { public override List<SubTwo> Get() { } } I want to create an abstract method that returns whatever class the concrete sub class is. So, as you can see from the example, the method in SubOne should return List<SubOne> whereas the method in SubTwo should return List<SubTwo> . What type do I specify in the signature declared in the Base class ? [UPDATE] Thank you for the posted answers. The solution is to make the abstract class generic, like such: abstract class Base<T> { public abstract List<T> Get(); } class SubOne : Base<SubOne> { public override List<SubOne> Get() { } } class SubTwo : Base<SubTwo> { public override List<SubTwo> Get() { } }
Tags (comma-separated)
Save Edits
Cancel