Use for Enumerations

Enumerations provide a way to define symbolic constants that belong together in a logical fashion. Two different uses exist. One is to represent constants that represent distinct values, such as values DayOfWeek.Monday through DayOfWeek.Sunday. It doesn’t make sense to try to combine two such values into a new one.

The second use is with flags, where values can be combined meaningfully. For instance, consider file I/O access modes FileAccess.Read and FileAccess.Write, which are very useful when combined to open a file for read and write.

Where logical operators come into play is with flag-based enums. Enumerations have an underlying integral type, and each member of the enumeration has a value of that type. By declaring those ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.