this. vs base. for inherited protected non-virtual methods?

Whithin my sub-class, should I refer to an inherited protected non-virtual method as this.Method() or base.Method()?

Using this would allow me to easily hide the method with a new method of the same name. Should calls to the method explicitly specifiy base only when it is certain that only the base class' implementation specifically needs to be called?

Answers


Call always using this.Method().

If you hide the method, you'll probably want to call the new method instead of the one in the base class. On the other hand, if you make the base class' method virtual, you'll probably want to make your code to call if in a polymorphic way.

It's hard to predict the future, but these scenarios seems more likely to happen.


If you're ever going to add a member named Method in your sub-class and still want to invoke the inherited method, you should use base.Method(). Adding members named Method in more derived classes will not change the meaning of this.Method() invocation.


Need Your Help

Why is NServiceBus receiving notifications from two different servers?

msmq nservicebus publish-subscribe

My app has two components. One is a notifier process (Notifier) that runs on a media server and publishes a message using NServiceBus when a file is modified. The other is a MVC web application

Show part of next and prev slides in owl Carousel 1.3.3

javascript jquery slider owl-carousel

I'm currently using owlcarousel 1.3.3, and I would like on mobile device to show current slide and a part of next slide.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.