Confused about “override” vs. “new” in C#

前端 未结 4 1063
粉色の甜心
粉色の甜心 2020-12-09 16:03

I\'m having the following classes:

class Base
{
    public virtual void Print()
    {
        Console.WriteLine(\"Base\");
    }
}

class Der1 : Base
{
    p         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 16:31

    override will replace the previous method, but as your Der1 class doesn't override Print() (it Shadows it, to use a VB-ism), then the most overriden verion of Base's Print() is called, which happens to be the version it defines

提交回复
热议问题