Quick C# Question

Bleh, no way. In fact, I think I even read a blog entry from somewhere that even said that constantly referencing this is a performance drain. Not sure how true that is, but even so…

I have to agree with Chris that this is both a needless and useless rule. The token "this->in C++, the precursor to “this.” in C#, was intended as a way to refer to the current object where ambiguity may exist.
I especially liked the comment in the reference which justifies this by saying that an added benefit is that Visual Studio uses it as a hint.
BTW:
Having been a developer on some of AT&T’s compilers back in the 80’s, I believe I am safe in saying the only impact that using “this.” in a statement can have is that it hints to the compiler that it only needs to look for the method/attribute in the current class hierarchy and therefore may (remember I said may) speed up the symbol lookup in the compiler. At execution time the runtime still needs a pointer to the current object to access virtual functions and attributes overloads. All other methods and attributes will ignore the token.

the underscore is incredibly ugly and I get rsi from hitting the shift button, please dont copy this idiom from c++ days

or we could go down the route of hungarian notation, for those who dont know what that is then thank your blessings…

I cant resist to respond on this topic, because it’s exactly what i’ve been talking about with my co-workers (non-embedded development).

The use of the underscore is indeed very ugly (hungarian notation is much worse) but it has one amazing benefit: you instantly see that you are using private member variables that contain the state of the object and may cause side effects. Today you can easily solve that by using an automated property ( public string Name { get; private set; } ) but that wasn’t around at the time…

On my teams, member variables always start with “my” - myLED, myCounter, myNativeTreeFrogLogger, etc. This makes it clear to us that something is a local class member in a way that isn’t ugly - to us.

Let us not forget the m_ convention used by MS in MFC.

I have settled on the “this.” notation when needed, and the time it’s needed is usually properties and constructors.

this is totally ok when you actually need it. You should not, however use it constantly because it is redundant.