I faced unexpected (unexpected for me) method call in classes described like this:
class Program
{
static void Main(string[] args)
{
int param = 5;
var item = new Derived();
item.DoWork(param);
Console.ReadLine();
}
}
class Derived : Base
{
public override void DoWork(int param) { Console.WriteLine("derived int"); }
public new void DoWork(double param) { Console.WriteLine("derived double"); }
}
class Base
{
public virtual void DoWork(int param) { Console.WriteLine("base int"); }
public virtual void DoWork(double param) { Console.WriteLine("base double"); }
}
I would expect that output is: "derived int", but strangely it's "derived double". If I change new keyword to override then I see expected output"derived int". Seems I miss something related to inheritance logic.
Is there somebody can explain this behavior?