在下面的例子中,会发生什么?C#隐藏成员
class Base {
public int abc = 3;
}
Class Derived : Base {
public int abc = 2;
}
static void Main() {
Derived blah = new Derived();
Console.WriteLine(blah.abc);
}
我敢肯定,你会看到“2”你的控制台上,但我在读什么(看到)反对一切......
为什么你会看到“3”,而不是' 2' ?我认为衍生类的成员'隐藏'基类的相同成员...
打我吧。好答案! – 2010-01-06 20:29:21
嗯,我以为这年龄以前,但我总是得到: “错误CS0106:修饰符'重写'不适用于此项” – Xenoprimate 2010-01-06 20:40:50
您需要添加'虚拟'到基类的属性,以便使用'覆盖派生类。 – 2010-01-06 20:58:04