April 2018
Intermediate to advanced
292 pages
6h 44m
English
Apart from structs, the value types contain enumerations. Each has a set of named constants to specify the available set of values. For instance, you can create the enumeration for available languages or supported currencies. An example definition is as follows:
enum Language { PL, EN, DE };
Then, you can use the defined enumeration as a data type, as shown as follows:
Language language = Language.PL;
switch (language)
{
case Language.PL: /* Polish version */ break;
case Language.DE: /* German version */ break;
default: /* English version */ break;
}
It is worth mentioning that enumerations allow you to replace some magical strings (such as "PL" or "DE") with constant values and this has a positive impact on code quality.