standards-c-sharp

Naming conventions

Naming conventions are pretty arbitrary, so long debates over them are not productive. The important thing is consistency across the code base. If our chosen conventions don’t align with your favorites, then we are truly sorry, but it is impossible to please everyone. We have to pick something, and there are much more important things to worry about.

We follow the default naming conventions suggested by Resharper. This way, out of the box all developers can be warned when a convention is violated, and provided with a quick-fix. Resharper’s naming conventions are pretty uncontroversial, except perhaps for the following:

Private fields

Use _myPrivateField rather than this.myPrivateField.

Don’t

public class MyClass
{
    private int myInt;
    
    public MyClass(int myInt)
    {
        this.myInt = myInt;
    }
}

Do

public class MyClass
{
    private int _myInt;
    
    public MyClass(int myInt)
    {
        _myInt = myInt;
    }
}

Constants

Use MY_CONSTANT rather than MyConstant.

Don’t

public const int AgeOfEarthInYears = 6000;

Do

public const int AGE_OF_EARTH_IN_YEARS = 6000;