privateMembers?


How do you name your private members?


camelCased or PascalCased?


I think the use of camelCase syntax to name the private members provides a high level of readibality because you know where you are (Public or private) without to look to the member definition.


However, reading code from GDN, people prefer to use PascalCase for everything. All the documentation I’ve found talking about this topic, only covers Public members so, I suppose you should have freedom to name your privates as you want, but inside a team a general coding standard is a good thing.


What do you think?

Comments (18)

  1. I’d recomend using camelCase for private member and Pacal for public.

    some people also prefix private members with "_", but I find it messes up intellisense 😉

  2. I believe that FxCop requires camelCase. I try to keep my systems as FxCop compatible as possible.

  3. Tim Marman says:

    Ditto (although for readability’s sake, not to appease the FxCop gods 🙂

  4. Jake Good says:

    I tend to use camelCase for private and public and PascalCase for classes .. that’s how I can keep things straight..

    IMHO

    Jake

  5. Mitch Walker says:

    camelCase and I prefix all access to them using "this." to easily identify what is a member versus local, etc.

  6. Because I use a m_ prefix I find PascalCase easier to read:

    m_firstName

    m_FirstName

  7. Jan says:

    I use

    _firstName

    It works both in C# and VB.NET.

  8. camelCased with an underscore in front of it.

    _firstName, just as Jan.

  9. Johnny Hall says:

    _firstName for me.

    And I don’t prefix them with this. either when accessing them.

    Public = FirstName

    Private = _firstName

    local = firstName

    That’s why I use the underscore, to distinguish between local and private. Without it, it’s possible to get clashes and it makes the code more readable (IMO).

  10. Dave L says:

    I prefer _camelCase for private and PascalCased for public

  11. Frans Bouma says:

    _camelCased for privates, PascalCased for public, camelCased for method parameters, PascalCased for method names, class names etc.

    It’s mandatory you distinguish the private member variables with a ‘_’ or m_ or similar from the properties with perhaps the same name. Also Johnny Hall’s arguments are very good.

  12. AndrewSeven says:

    I don’t really like the idea of _privateVar but in practice it makes my life easier than privateVar

  13. George Chernyha says:

    camelCase for privates, and method parameters, PascalCase for classes, interfaces, method names, and publics.

  14. Jason Raneses says:

    I understand the rationale behind using an underscore prefix for privates, however, I feel doing so is just as bad as using Hungarian notation in a lot of ways. _firstName does not follow the naming guidelines, nor does m_firstName. By using something as simple as firstName for a private variable, and then having a public property named FirstName, you then also code yourself into a corner because it’s not recommended to have public and private members differ only by case. It would be nice to see something formally recommended by the powers that be that adheres to the rules and passes FxCop validation.

  15. Chris Hynes says:

    I use camelCase for private fields, _camelCase for fields that back properties, and PascalCase for everything else.

  16. Eddie Velasquez says:

    m_camelCase for private fields.

  17. Rido has post a kind of poll about the naming of private members. Some comments on using PascalCase,

Skip to main content