How do you distinguish properties from constants if they both use PascalCasing for naming?

As stated in the framework design guidelines and the WWW in general, the current guide should name your constants like this

LastTemplateIndex


Unlike LAST_TEMPLATE_INDEX

With the PascalCasing approach, you can differentiate between property and constant.
ErrorCodes.ServerDown

excellent. But what about the private constants in your class? I use quite a few of them to denote magic numbers .. or for expected values ​​in my unit tests and so on.

The ALL_CAPS style helps me understand that it is a constant.

_testApp.SelectTemplate(LAST_TEMPLATE_INDEX);

Disclosure: I have been using the SCREAMING_CAPS style for a while for + constants. I find it more readable than squishedTogetherPascalCasedName. This is actually STANDS_OUT in a block of text

+2


a source to share


1 answer


We create a separate static class to place our constants in and tag it Constants.

Thus, when we refer to a constant, always Constant.YourConstantHere



So

  class NewClass
    {

        static class Constants
        {
            public const int T = -1;
        }
    }

      

+2


a source







All Articles