I have a co-worker who uses a C# refactoring tool. The tool for some reason perfers:
this.Foo()
over
Foo()
Now we’ve asked him to turn it off simply because it’s annoying to have all the code re-written automatically, but that’s not the point.
Am I missing something, or is this just wrong? Why on earth would I want this.Foo()?
As other answers here point out, this is largely a matter of style.
Many times a call to
Foo()would be unambiguous without thethis., but there are times where it might add clarity. For example:In this case, the
this.prefix helps to make the method invocation stand out from the delegate invocations.Is this necessary? No, and Lasse V. Karlsen correctly points out that the
this.is just a surrogate for a naming convention that makes it unambiguous.But I find that I will frequently use the
this.Fooprefix on local properties for a similar reason, where again it is more a matter of style.