Enumerations

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.

Get C# Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.