小编Gal*_*hen的帖子

C#使用继承重载方法调用

我想知道调用打印"double in derived"的方法的原因是什么.我没有在C#规范中找到任何线索.

public class A
{
    public virtual void Print(int x)
    {
        Console.WriteLine("int in base");
    }
}

public class B : A
{
    public override void Print(int x)
    {
        Console.WriteLine("int in derived");
    }
    public void Print(double x)
    {
        Console.WriteLine("double in derived");
    }
}



B bb = new B();
bb.Print(2);
Run Code Online (Sandbox Code Playgroud)

c# inheritance overloading

12
推荐指数
1
解决办法
134
查看次数

标签 统计

c# ×1

inheritance ×1

overloading ×1