For those of you that use the underscore prefix for private class members in C# (i.e. private int _count;), what do you use for private constants? I'm thinking the following but am curious as to what others are doing.
private const int _MaxCount;
For those of you that use the underscore prefix for private class members in C# (i.e. private int _count;), what do you use for private constants? I'm thinking the following but am curious as to what others are doing.
private const int _MaxCount;
C# and .NET naming conventions discourage all prefixes (e.g. C
, i
, s_
, g_
, m_
, _
) except "I
" for interface names and "T
" for type parameters.
Well, private is private, so chose the convention you like best. I personally use PascalCasing, e.g:
private const int SomeConstant = 42;
This is what MSDN has to say about it:
The naming guidelines for fields apply to static public and protected fields. You should not define public or protected instance fields:
The naming guidelines are available here:
http://msdn.microsoft.com/en-us/library/ms229002.aspx
As Mehrdad said, prefixes are specifically discouraged.
That said, they are just guidelines more than hard rules. Personally, I use an '_' prefix, but only for private members that directly provide the backing store for a public property, and then the names will otherwise match exactly.
There's no specific guidance for constants, so the Capitalization Conventions rules probably still fit.
I'm using:
private const int MAX_COUNT = 42;
I do not use PascalCasing because that's my standard for properties.
I do not use camelCasing because that's my standard for local variables.
I do not use _camelCasing because that's my standard for private fields.
I do not use _PascalCasing because IMO it's hard to distinguish it from _camelCasing.