Specifying the return type of an abstract method from a Base Class according to a Sub Class

前端 未结 4 1271
终归单人心
终归单人心 2020-12-15 07:15

I have the following structure:

abstract class Base {
        public abstract List<...> Get(); //What should be the generic type?
}

class SubOne :         


        
4条回答
  •  不知归路
    2020-12-15 07:49

    Try this:

    public abstract class Base {
      public abstract List Foo();
    }
    
    public class Derived : Base {   // Any derived class will now return a List of
      public List Foo() { ... }     //   itself.
    }
    

提交回复
热议问题