我猜是一个基本问题,但是如果我希望一个对象拥有另一个类型为 A 或 B 的对象,那么使用该对象的应用程序如何访问特定属性?例如
public abstract class Animal
{
private int Age;
// Get Set
}
public class Tiger: Animal
{
private int NoStripes;
// Get Set
}
public class Lion : Animal
{
private bool HasMane;
// Get Set
}
public class Zoo
{
private Animal animal;
// Get Set
}
public static void Main()
{
Zoo zoo = new Zoo();
zoo.animal = new Tiger();
// want to set Tiger.NoStripes
}