Enum types, FlagsAttribute & Zero value – Part 2

In my previous post I wrote about why you should pay attention when using enum value Zero.
After reading that post you are probably thinking like Benjamin Roux: Why don’t you start the enum values at 0x1?
Well I could, but doing that I lose the ability to have Sync and Async mutually exclusive by design. Take a look at the following enum types:

[Flags]
public enum OperationMode1
{
    Async = 0x1,
    Sync = 0x2,
    Parent = 0x4
}

[Flags]
public enum OperationMode2
{
    Async = 0x0,
    Sync = 0x1,
    Parent = 0x2
}

read more

Enum types, FlagsAttribute & Zero value

We all know about Enums types and use them every single day. What is not that often used is to decorate the Enum type with the FlagsAttribute.

When an Enum type has the FlagsAttribute we can assign multiple values to it and thus combine multiple information into a single enum.

The enum values should be a power of two so that a bit set is achieved.

Here is a typical Enum type:

public enum OperationMode
{
    /// <summary>
    /// No operation mode
    /// </summary>
    None = 0,
    /// <summary>
    /// Standard operation mode
    /// </summary>
    Standard = 1,
    /// <summary>
    /// Accept bubble requests mode
    /// </summary>
    Parent = 2
}

read more