Constants


Constants are the values that can't be changed and are known at compile time.

  • User-defined types (e.g. class, struct, array) cannot be declared as constants.
  • Only built-in types (e.g. string, int, bool, etc.) can be declared as constants.

The const modifier is used to declare constants.

class MyClass
{
    public const string MyConstant = "This is a constant";
}