Search code examples
c#naming-conventionsstylecopacronym

Naming Convention for constant Acronyms


Naming convention according to StyleCop for constants is Pascal.

For example

private const double InchToMm= 2.54;

What about naming convention for acronym?

private const int Dpi = 96;

or

private const int DPI = 96;

Solution

  • The Framework Design Guidelines from Microsoft says:

    The PascalCasing convention, used for all identifiers except parameter names, capitalizes the first character of each word (including acronyms over two letters in length), as shown in the following examples:

    PropertyDescriptor

    HtmlTag

    A special case is made for two-letter acronyms in which both letters are capitalized, as shown in the following identifier:

    IOStream

    The camelCasing convention, used only for parameter names, capitalizes the first character of each word except the first word, as shown in the following examples. As the examples also shows, two-letter acronyms that begin a camel-cased identifier are both lowercase:

    propertyDescriptor

    ioStream

    htmlTag

    But nevertheless, these are guidelines and conventions and not laws. If you like to take another convention, just use it. But then always and never mix up.