In the example I was expecting to get Third as output since class Third has an exact signature match to the Print call, but the output is Second. Why that happens?
class First
{
public virtual void Print(string x)
{
Console.WriteLine("First");
}
}
class Second : First
{
public void Print(object x)
{
Console.WriteLine("Second");
}
}
class Third : Second
{
public override void Print(string x)
{
Console.WriteLine("Third");
}
}
class Program
{
static void Main(string[] args)
{
string sss = "lalala";
Third t = new Third();
t.Print(sss);
Console.ReadLine();
}
}
See here:
Thus, overriden method in the
Thirdis not applicable andSecond.Print(object)hides base class implementation and becomes single candidate.