相关疑难解决方法(0)

为什么这个C#代码会返回它的功能

有人可以帮我理解为什么这段代码片段返回"Bar-Bar-Quux"?在阅读界面后,我很难理解这一点.

interface IFoo
{ 
    string GetName();
}

class Bar : IFoo
{
    public string GetName() { return "Bar"; }
}

class Baz : Bar
{
    public new string GetName() { return "Baz"; }
}

class Quux : Bar, IFoo
{
    public new string GetName() { return "Quux"; }
}

class Program
{
    static void Main()
    {
        Bar f1 = new Baz();
        IFoo f2 = new Baz();
        IFoo f3 = new Quux();
        Console.WriteLine(f1.GetName() + "-" + f2.GetName() + "-" + f3.GetName()); …
Run Code Online (Sandbox Code Playgroud)

c# interface code-snippets

37
推荐指数
2
解决办法
2510
查看次数

标签 统计

c# ×1

code-snippets ×1

interface ×1