C# and method hiding

后端 未结 9 1229
悲&欢浪女
悲&欢浪女 2021-01-03 07:48

Per MSDN, the \"new\" keyword when used for method hiding only suppresses a warning.

http://msdn.microsoft.com/en-us/library/435f1dw2.aspx

Do I really need

9条回答
  •  庸人自扰
    2021-01-03 08:24

    It's part of C#, just like ref and out. The idea is to warn you that your API is overriding a method which could affect code that relies on sub/superclasses of your class.

    Placing the new keyword forces you to think about whether that is really what you intended to do or not, just like requiring ref or out so that you have to think about the contract your code is providing.

提交回复
热议问题