I've read numerous documents and books and seen various references on how to refer to private member variables in a class. I have been inconsistent myself depending on what I'm doing and I'm wondering what some others out there use or recommend.

Here are the ways I know of:

  • _memberVariable
  • m_MemberVariable
  • m_memberVariable
  • this.memberVariable

For instance, Juval Lowy recommends m_MemberVariable. However, everything else I've read says "Hungarian notation, don't go there."

Here is my take. I like using this. because when I type the period Intellisense kicks in any my lazy brain doesn't have to remember all the member variables in my class (I just discovered control-spacebar though). However, writing this. everywhere clutters up the code. I also don't like the underscore style cause it can sometimes look quite funny:

  • this._memberVariable
  • (string)_memberVariable etc.

I like just using memberVariable and only using this in the constructor or any method where I might be taking a parameter named memberVariable. Make sense?

For me this is the only area of the coding standards that are completely inconsistent depending on what I read and who is writing the code. Further I've noticed that within the .NET framework base classes there is usage of both the Hungarian style and the underscore style.