From the code below I wanted to know What is the difference between MyMethod2() and MyMethod3(). Why has .net provided does not give compile error for not mentioning the new keyword or in other words why has .net provided new keyword, if both implemnetation are same.
public class MyBase
{
public virtual void MyMethod2()
{
//do something
}
public virtual void MyMethod3()
{
//do something
}
}
public class MyDerived :MyBase
{
public void MyMethod2()
{
base.MyMethod2();
}
public new void MyMethod3()
{
base.MyMethod3();
}
}
static void Main(string[] args)
{
MyBase myClass = new MyDerived();
myClass.MyMethod2(); //calls base class
myClass.MyMethod3(); //calls base class
}