Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stylecop tells me to add this keyword, but it's redundant - any performance implications?

Tags:

c#

.net

this

I use Stylecop for Resharper and whenever I call something in my class, Stylecop tells me to use the this keyword. But the IDE says this is redundant code (which it sure is), so why should I use the this keyword?

Does redundant code mean its not needed (obviously) and the compiler won't even do anything with the this keyword? So I assume the this keyword is just for clarity.

Also, with the CLR, do things like this fall consistently across languages? So if the answer is that the compiler doesn't even touch the this keyword and it is just for presentation and clarity, then the same is true for VB.NET? I assume it is all for clarity as stylecop keeps an eye on this and Fxcop (which I will use later on) keeps an eye on my code's quality from a technical point of view.

Thanks

like image 352
GurdeepS Avatar asked Jan 16 '09 02:01

GurdeepS


1 Answers

It's for clarity and to prevent any ambiguity between a class member and a local variable or parameter with the same name.

The IL it compiles to will not be any different.

like image 122
Andrew Kennan Avatar answered Oct 03 '22 08:10

Andrew Kennan