About This eBook by Bart De Smet

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Flags

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

public enum FileMode{    CreateNew = 1,    Create = 2,    Open = 3,    OpenOrCreate = 4,    Truncate = 5,    Append = 6,}

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

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required