I am assuming MyMethod is something defined in the base class but *not*
overridden in the inheriting class? In that case, these are the same.
However, if MyMethod is overridden in the inheriting class, then these 2
things are completely different. The first one calls the overridden version,
and the second one calls the base version.
So you want to be careful in how you typically call these methods, to make
sure you are calling the one you really want.
In the case where MyMethod may or may not be overridden, it seems that
always calling this.MyMethod is safest. If there is a version in the
inheriting clas - that will get called. If not, the base version will get
called. So I would only use 'base' to prefix things where you explicitly
want to call the base class's version for whatever reason, regardless of
whether or not there is a version in the inheriting class.
"Dave Veeneman" <da****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I'm using inheritance more than I used to, and I find myself calling a lot
of base class methods. I generally call a base method from a dreived class
like this:
this.MyMethod();
I'm finding it somewhat confusing when I look at the code later, because I
expect to find a method called MyMethod() in the derived class.
I think C# would let me call a base class method from a derived class like
this:
base.MyMethod();
This would make it clear that the method being called is a base class
method. From the standpoint of clarity, I like it.
But, are there other reasons I couldn't call a base class method like
that? Reasons why I shouldn't? Thanks.
Dave Veeneman
Foresight systems