In this short tutorial, you will learn the key points of C# constants.
Definition
A constant is a variable whose value cannot be changed throughout its lifetime, and it is defined with the keyword const.
const string testStr = "This is a constant";
Characteristics
- Constants must be initialized when they are declared. And can never be overwritten after a value been assigned.
- The value of a constant must be computable at
compiletime. As thecompilerreplaces the variable with its values everywhere it is used. - Constants are always implicitly
static.