Bit Flag Enums : enum base type « Data Type « C# / CSharp Tutorial






using System;
[Flags]
enum BitValues: uint
{
    NoBits = 0,
    Bit1 = 0x00000001,
    Bit2 = 0x00000002,
    Bit3 = 0x00000004,
    Bit4 = 0x00000008,
    Bit5 = 0x00000010,
    AllBits = 0xFFFFFFFF
}

class MainClass
{
    public static void Member(BitValues value)
    {
        Console.WriteLine(value);
    }
    public static void Main()
    {
        Member(BitValues.Bit1 | BitValues.Bit2);
    }
}
Bit1, Bit2








2.37.enum base type
2.37.1.Convert enum to int
2.37.2.Assign int value to all elements in an enum
2.37.3.Assign int value to the first element in an enum
2.37.4.Define enumeration base types
2.37.5.Bit Flag Enums
2.37.6.Using Bit flags when declaring the enum
2.37.7.Print out string version of an enum value
2.37.8.Using a base type of long when defining an enum
2.37.9.Using Operators with Enumerations
2.37.10.enum based on byte
2.37.11.enum based on byte, and convert enum variable back to byte