为什么闲置代码的结果是:
A
类 A 类 A
类
public class A {
public virtual void f() {
Console.WriteLine("Class A");
}
}
public class B : A {
public virtual void f() {
Console.WriteLine("Class B");
}
}
public class C : B {
public override void f() {
Console.WriteLine("Class C");
}
}
//...
static void Main(string[] args) {
A[] array = new A[3];
array[0] = new A();
array[1] = new B();
array[2] = new C();
for(int d = 0; d < 3; d++)
array[d].f();
}