Valid applications of member hiding with the new keyword in c#

后端 未结 7 2339
终归单人心
终归单人心 2021-02-18 16:22

I\'ve been using c# since version 1, and have never seen a worthwhile use of member hiding. Do you know of any?

7条回答
  •  情书的邮戳
    2021-02-18 16:44

    We had a class that inherited from the WebControl class. When we upgraded from 3.5 to 4.0, the way that some of our attributes (mainly around onclick and javascript) changed quite radically.

    We could not change how the AttributeCollection class was handled by the WebControl, so what we did was implement the same methods and properties of the AttributeCollection in our custom collection and hid the AttributeCollection property with our own.

    None of the accessing code changed, and we were able to correctly implement how to handle the attributes in our classes. Now no one needs to know what we did to fix the problem. All they need to know is that they call Attributes.Add like normal, and we fix things under the hood.

提交回复
热议问题