Is method hiding ever a good idea

前端 未结 8 1845
死守一世寂寞
死守一世寂寞 2020-12-01 09:29

In C# the new modifier can be used to hide a base class method without overriding the base class method.

I\'ve never encountered a situation where hidin

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 09:47

    There are rare, but very good, reasons to use method hiding. Eric Lippert posted a great example on his blog:

    interface IEnumerable : IEnumerable { 
      new IEnumerator GetEnumerator(); 
    }
    

    However, I think hiding should be the exception, and only used sparingly.

提交回复
热议问题