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

后端 未结 7 2370
终归单人心
终归单人心 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:42

    Making the return type more explicit - for example SqlConnection.CreateCommand returns a SqlCommand, not a DbCommand. Actually, it looks like this isn't declared new, but that would be one of the few times I would use this; most times it is evil.

    Another use: remove inherited attributes from a member.

提交回复
热议问题