Skip to main content

Configure Visual Studio to Name Private Fields with Underscore

Most C# coding standards recommend using camelCase for local variables and _camelCase for private or internal. Unfortunately, out of the box Visual Studio just uses camelCase for these fields, which makes typical dependency injection scenarios annoying in constructors:

Steps:
  1. Click on Tools in the menu.
  2. Click on Options.
  3. Click on Text Editor.
  4. Click on C#.
  5. Click on Code Style.
  6. Click on Naming.
  7. Click on Manage naming styles.


In the Naming Style dialog. Specify the following (see image below):

  • Naming Style: _fieldName
  • Required Prefix: _
  • Capitalization: camel Case Name
Once you add it, your list should look like this


Comments