O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required