#959 – Don’t Use Double Underscores at the Start of an Identifier

When naming identifiers in C#, you can use the underscore (‘_’) character anywhere in the identifier name, including at the beginning of the name.

Some people use identifiers that begin with a single underscore for private fields (e.g. _name_age).  This use is no longer recommend.  You should instead just use camelCasing for private fields.  If you want to make clear that the identifer is a member variable, you can use the this keyword (e.g. this.namethis.age).

You should, however, never use a double underscore at the start of an identifier name.  There are already several reserved keywords that start with a double underscore (e.g. __reftype, __refvalue).  The double underscore notation is meant to be used for these reserved keywords and future revisions to C# may add new keywords that may then conflict with any identifiers that you have in your code.

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

2 Responses to #959 – Don’t Use Double Underscores at the Start of an Identifier

  1. Joerg says:

    Hi Sean,

    why is it not recommended to use single underscore for private fields? Actually I switched from camelCase to _camelCase for my private Fields, since it makes finding my private fields in IntelliSense a lot easier. If I want to use my private field somewhere I just type ‘_’ and Intellisense shows me all my private fields instead of a whole bunch of fields, properties and methods.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: