C# private instance variable Naming Convention.

D3v01D

Gawd
Joined
Oct 6, 2005
Messages
557
Greetings to the programming forum, this is my first post here. :D

Last week I decided to learn how to program. Language of choice is C#.

My problem is I have one source telling me private instance variables should begin with a lower case letter (like 'p')
and another telling me they should begin with an underscore ' _ '

Can someone please enlighten me ?

TIA


 
Stictly speaking it doesn't matter all that much as long as you're consistent. I use _ myself because it's visually easy to distinguish.
(Besides, I think pThis is a bit uglier than _this, but that's definitely a personal thing.)
 
I've read that as well. Although, I use camel case for private methods and pascal case for public methods.

For properties, I use pascal case for the public property and "m_MyPrivateVariable" for the private variables that have properties associated with them.

I don't think I have a particular style for private variables that don't have properties associated with them though. I think I just camel case them just like I do for local variables.
 
I only PascalCase for class names, absolutely everything else gets simple lowercase or camelCase.
(Except for C, where I use underscore_joins for some reason.)

I'm not very fond of hungarian notation either, though I use the postfix variation now and then.

... Can we have a brace style / indentation war later?
(K&R is the only true style! All others are an affront to serious programmers! :D )
 
I do the underscoure + camelCase notation... the sole reason being it makes it easier to distinguish local variables from instance/static variables and avoid variable name clashing. This is more important in working in a multidev project and when methods can contain 300+ lines of code.
 
HJB417 said:
I do the underscoure + camelCase notation... the sole reason being it makes it easier to distinguish local variables from instance/static variables and avoid variable name clashing. This is more important in working in a multidev project and when methods can contain 300+ lines of code.

Uh, methods shouldn't be 300+ lines of code.

My company uses _ and I use _ for my projects.
 
Back
Top