Skip to main content

Posts

Showing posts from March, 2025

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: Click on Tools in the menu. Click on Options. Click on Text Editor. Click on C#. Click on Code Style. Click on Naming. 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