Last post Nov 14, 2016 12:06 PM by Cathy Zou
Nov 12, 2016 05:07 PM|vinodkpasi|LINK
What is the naming convention for private constant field and
public constant field in C#?
Nov 12, 2016 06:02 PM|senthilwaits|LINK
The recommended way is to use Pascal casing for constants.
private const int TheAnswer = 42;
public const string TheAnswer = "42";
You can use StyleCop
which analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project. StyleCop has also been integrated into many third-party development tools.
You can also refer
Nov 12, 2016 08:16 PM|Nasser Malik|LINK
I don't see any special reason to use Pascal instead of camel. Usually I use Pascal in case of enum but use camel when I declared private or public constant. You can notice the same on msdn
msdn also using Pascal
But resharper and
dofactory suggest to use Pascal
private const int MyInt = 10;
public const string MyString = "This is a constanct string";
To define constant values of integral types (int, byte, and so on) use an enumerated type. For more information.
To define non-integral constants, one approach is to group them in a single static class named Constants. This will require that all references to the constants be prefaced with the class name, as shown in the following example.
static class Constants
public const double Pi = 3.14159;
public const int SpeedOfLight = 300000; // km per sec.
static void Main()
double radius = 5.3;
double area = Constants.Pi * (radius * radius);
int secsFromSun = 149476000 / Constants.SpeedOfLight; // in km
Nov 12, 2016 08:57 PM|KathyW|LINK
Pascal is recommended in several articles, but the fact is, naming casing standards are up to you. All that matters is that if you are working in a team, you follow the same standards and are all consistent, for ease of reading or modifying each other's
code. If you are working solo, feel free to follow recommendations, or make your own.
Nov 14, 2016 12:06 PM|Cathy Zou|LINK
In Pascal casing, the first letter of an identifier is capitalized as well as the first letter of each concatenated word. This style is used for all public identifiers within a class library, including namespaces, classes and structures, properties, and
In Camel casing, the first letter of an identifier is lowercase but the first letter of each concatenated word is capitalized. This style is used for private and protected identifiers within the class library, parameters passed to methods, and local variables
within a method.
For more information, please refer to the following links: