Saturday, April 20, 2024 16:21

Posts Tagged ‘constants’

Enumerations

Sunday, July 16th, 2017

Enumerations are structures which resemble classes but differ from them in that in the enum body we can declare only constants. A variety of logically connected constants can be linked by means of language. These language constructs are the so-called enumerated types.… Read more

Constants

Saturday, July 1st, 2017

Just like constants in mathematics, C# defines special fields of classes called constants. Like their name hints, once declared and initialized, constants maintain their values, forbidding their further modification.

There are two types of constants:

  • constants for which the value is set during the compilation (compile time constants)
  • constants which have their value set during the execution (run-time constants)

Compile time constants are declared using the C# modifier const:

A secret not many C# programmers know is that compile time constants are static fields, even if they do not contain the static keyword, and the compiler forbids its usage in the declaration.… Read more


Follow the white rabbit