O'Reilly logo

C# 4.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

Flags

Besides their use for discrete named constants, enums can also be used to describe flags. For example, System.IO defines the FileOpen enum as follows:

image

This nonflags enum is passed to APIs like File.Open to specify which mode to open the file with. Basically, this enum corresponds to Win32 constants passed to CreateFile. In fact, the values used for the different FileMode members directly map onto those used on the Win32 API being called. It’s clear that something like FileMode describes a set of discrete values that are mutually exclusive. You can only “open” the file in any of the six available modes. Combining things such as Append with ...

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