Using the 'new' modifier in C#

后端 未结 3 2130
醉话见心
醉话见心 2020-12-11 01:48

I read that the new modifer hides the base class method.

using System;

class A
{
    public void Y()
    {
        Console.WriteLine(\"A.Y\");
         


        
3条回答
  •  自闭症患者
    2020-12-11 02:21

    The type of the object is A, but ref2 does not access the version of Y() that is defined in the B class because that method is declared with the new modifier, not the override modifier. As a result, a ref2 object displays the same description as an A object.

提交回复
热议问题