What if I don't heed the warning “hides inherited member. To make the current member override that implementation…”

前端 未结 3 1292
既然无缘
既然无缘 2021-02-02 07:36

This is maybe a fine point, but it concerns the warning that the compiler issues if you do something like:

class A
{
    public virtual void F() { }
}
class B :          


        
3条回答
  •  时光取名叫无心
    2021-02-02 08:25

    No, the default behaviour is exactly the same as if you use new, other than whether the warning is given. In my experience you more often actually want to specify override instead of new, as it's usually just a case of forgetting to explicitly override.

    If you really do want a completely separate method, and if you've got the option of using a different name instead, I'd take that approach. Having one method hiding another usually reduces readability significantly IMO. It's not too bad if the purpose is to just give a more specific return type (and you make sure the more weakly typed method returns the same value), but that's a pretty rare case.

提交回复
热议问题