+ 4
Var vs const
// can we write ? const int x; x=9;
4 Respuestas
+ 8
No, this will give a compiler error. Constants in C# must be given a value when they are declared.
+ 6
No, this will cause an error coz constant must be initialized with a value when declared nd it can't be changed, once it is assigned.
+ 3
Just to add to what Lauren said.
Constant variables can not be changed during runtime of your program.
+ 2
The difference between a constant and a variable is that a variable can change its value (like int x=5; some code x = 9.)
But a constant cannot be changed after you assign it to a value.