“ new”关键字不会被覆盖,它表示与基类方法无关的新方法。
public class Foo{ public bool DoSomething() { return false; }}public class Bar : Foo{ public new bool DoSomething() { return true; }}public class Test{ public static void Main () { Foo test = new Bar (); Console.WriteLine (test.DoSomething ()); }}这将显示为false,如果使用了覆盖,则其将显示为true。
(摘自Joseph Daigle的基本代码)
因此,如果您正在执行真正的多态性,则应 始终覆盖 。您需要使用“ new”的唯一地方是该方法与基类版本没有任何关系。



