0

Should const always be used?

5th Jul 2017, 4:40 PM
Alyson Jorge
Alyson Jorge - avatar
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.
5th Jul 2017, 4:54 PM
Bumpety
+ 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.
5th Jul 2017, 4:58 PM
AgentSmith
- 1
private const string MYCONST = "Const Keyword";
5th Jul 2017, 6:04 PM
Alyson Jorge
Alyson Jorge - avatar
- 1
private const string MYCONST; //Error
5th Jul 2017, 6:05 PM
Alyson Jorge
Alyson Jorge - avatar