You get a method that hides whether you specify "new", but this is not the same as overriding. Here is an example where they are different:
using System; class Base { public virtual void OverrideMe() { Console.WriteLine("Base.OverrideMe"); } public virtual void HideMe() { Console.WriteLine("Base.HideMe"); } } class Derived : Base { public override void OverrideMe() { Console.WriteLine("Derived.OverrideMe"); } public new void HideMe() { Console.WriteLine("Derived.HideMe"); } } class Test { static void Main() { Base x = new Derived(); x.OverrideMe(); x.HideMe(); } }
Output:
Derived.OverrideMe Base.HideMe
Despite the fact that the underlying HideMe method is virtual, it is not overridden in Derived , it is simply hidden - therefore, the method is still bound to the virtual method in Base , and what is being executed.
Hiding members is usually a bad idea, which makes code more difficult to understand. However, the fact that it is available is useful from the point of view of version control - this means that adding a method to the base class does not allow potential classes to override it unintentionally, and they can continue to work as before. That is why you get a warning.
source share