不知道
是不是你的Dog类定义的有问题啊
public class Dog
{
private string name;
public Dog(string name){
this.name = name;
}
}
List<Dog> list = new List<Dog>();
list.Add(new Dog("A"));
list.Add(new Dog("B"));
list.Add(new Dog("C"));
Dog dog = new Dog();
if(A is true) ((base)dog).PrintName();//调用父类方法
if(B is true) dog.PrintName();// 调用子类方法
因为通过virtual修饰父类方法,使包含子类的父类对象使用子类中重写后的该方法;而用new,子类对象只能使用自身该方法,不能调用父类中该同名方法。