I've read about new
keyword in method signature and have seen the example below on this post, but I still don't get why to write new
keyword in method signature. If we'll omit it, it still will do the same things. It will compile. There is gonna be a warning, but it will compile.
So, writing new
in method signature is just for readability?
public class A
{
public virtual void One() { /* ... */ }
public void Two() { /* ... */ }
}
public class B : A
{
public override void One() { /* ... */ }
public new void Two() { /* ... */ }
}
B b = new B();
A a = b as A;
a.One(); // Calls implementation in B
a.Two(); // Calls implementation in A
b.One(); // Calls implementation in B
b.Two(); // Calls implementation in B