Bol*_*lha 4 c# methods overloading resolution
在示例中,我期望获得第三个输出,因为第三类与Print调用具有精确的签名匹配,但输出为Second.为什么会这样?
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();
}
}
Run Code Online (Sandbox Code Playgroud)