【发布时间】:2025-11-24 22:50:01
【问题描述】:
我有这个抽象类:
abstract class Animal {
public abstract List<??????> getAnimals();
}
我想改变返回类型来做到这一点:
Animal animal;
if(/*Somthing*/){
animal = new Cat();
catList = animal.getAnimals();
}else{
animal = new Dog();
dogList = animal.getAnimals();
}
我想返回CatModelList 和DogModelList。
如果 dog 和 cat 以 Animals 为基础,这可能吗?如果不是我认为的答案,那么正确的做法是什么?
【问题讨论】:
标签: c# abstract return-type base-class