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

前端 未结 4 1270
终归单人心
终归单人心 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:55

    I don't think you can get it to be the specific subclass. You can do this though:

    abstract class Base {
            public abstract List Get(); 
    }
    class SubOne : Base {
        public override List Get() {
            throw new NotImplementedException();
        }
    }
    class SubTwo : Base {
        public override List Get() {
            throw new NotImplementedException();
        }
    }
    

提交回复
热议问题