constant is a variable whose value cannot be changed throughout its lifetime:
const int abc = 5; // This value cannot be changed
Constants have the following characteristics:
-
They must be initialized when they are declared, and once a value has been assigned, it can never be overwritten.
The value of a constant must be computable at compile time. Therefore, we can’t initialize a constant with a value taken from a variable. If you need to do this, you will need to use a readonly field.
Constants are always implicitly static. However, notice that we don’t have to include the static modifier in the constant declaration.