What is the capitalization conventions for protected field names in C#?
Is it _myVar (like private field) or MyVar (like properties)?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.Sign up to join this community
There is something that is called Design Guidelines for Developing Class Libraries which is written by Microsoft.
It says the following:
Do not provide instance fields that are public or protected.
Public and protected fields do not version well and are not protected by code access security demands. Instead of using publicly visible fields, use private fields and expose them through properties.
As well as:
Do use Pascal casing in field names
Do not use a prefix for field names. For example, do not use g_ or s_ to distinguish static versus non-static fields.
As for the
_ prefix, it's used just as often as the
this. convention (as far I've seen browsing source code in CodePlex/GitHub). ReSharper, for instance, promotes
_ in its naming checks.