C# Tutorial: Enums
Define enumerated types, use Flags enums for bit fields, and parse enums from strings.
Named constants
Enums give meaningful names to sets of related integer constants.
C# enums are strongly typed — you cannot accidentally use an invalid value or mix two different enum types.
What you'll learn in this C# enums tutorial
This interactive C# tutorial has 8 hands-on exercises. Estimated time: 15 minutes.
- Basic enum — Define an enum and use its values.
- Enum in switch — Switch on enums for exhaustive case handling.
- Custom underlying values — You can assign explicit integer values to enum members.
- Flags enum — `[Flags]` enums use powers of 2 to combine values with bitwise OR.
- Enum.GetValues — Iterate all values of an enum with `Enum.GetValues`.
- Enum.Parse and TryParse — Convert strings to enum values at runtime.
- Enum with methods via extension — Enums cannot have methods, but extension methods add behaviour.
- Enum as array index — Enum values as array indices create type-safe lookup tables.
C# Enums concepts covered
- Named constants