Back to course

Enums with Flags

C# Zero to Hero: Comprehensive Programming Masterclass

Enums as Bit Fields

You can use the [Flags] attribute to treat an enum as a bit field, allowing you to combine multiple values.

Example

csharp [Flags] enum Permissions { None = 0, Read = 1, Write = 2, Execute = 4 }

Permissions myPerms = Permissions.Read | Permissions.Write;

This is useful for settings where multiple options can be active at once.