小编rah*_*hul的帖子

为什么在C#中调用Grand parent虚函数

我有以下代码.任何人都可以回答为什么调用base-show方法而不是在这种情况下调用derive-show.在这种情况下,如何为derive和基类的show函数进行内存分配.

class OverrideAndNew : Derive
{

    public static void Main()
    {
        Derive obj = new Derive1();
        obj.Show();

        Console.ReadLine();
    }
}

class Base
{
    public virtual void Show()
    {
        Console.WriteLine("Base - Show");
    }
}

class Derive : Base
{
    protected virtual void Show()
    {
        Console.WriteLine("Derive - Show");
    }
}

class Derive1 : Derive
{
    protected override void Show()
    {
        Console.WriteLine("Derive1 - Show");
    }
}
Run Code Online (Sandbox Code Playgroud)

c# oop

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

标签 统计

c# ×1

oop ×1