0
Should const always be used?
4 Respuestas
0
If you have to declare a constant you should use the const keyword. You can't change its value und it is semantic sugar for your code. Also other developer can instantly see that this value will never changed. Anyway you should also name a constant in capital letters.
+ 2
The typical naming convention used for constants in C# is the pascal style. Basically first letter of each word is capitalized, not the entire word.
Example:
private const string MyConstantVariable;
And just use constants where the value itself is constant. For example, the value of pi is constant.
- 1
private const string MYCONST = "Const Keyword";
- 1
private const string MYCONST; //Error