An enum defines a group of named constants: enum Level { Low, Medium, High }.
Convert to text with ToString(), parse with Enum.Parse<Level>("High").
Enums work nicely with switch.
The underlying value is an int starting at 0 unless you assign values.
💡 Key Takeaways: C# Enums
Mastering C# Enums helps you write clean and reliable C# code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
C# Enums Code Example
C#
var status = OrderStatus.Shipped;
Console.WriteLine(status);
Console.WriteLine((int) status);
string message = status switch
{
OrderStatus.Pending => "Waiting for payment",
OrderStatus.Shipped => "On the way",
OrderStatus.Delivered => "Delivered!",
_ => "Unknown"
};
Console.WriteLine(message);
Console.WriteLine(Enum.Parse<OrderStatus>("Delivered") == OrderStatus.Delivered);
enum OrderStatus { Pending = 1, Shipped, Delivered }
Output
Shipped
2
On the way
True
Run this example on your own computer. The "Get Started" lesson shows how to set it up.
C# Enums Practice Exercises
Check what you learned in “C# Enums”.
/ 2 solved
Fill in the blank
Parse text into an enum value.
var s = Enum.<OrderStatus>("Delivered");
✓ Correct!Not quite. Try again.
Multiple choice
What is the underlying type of an enum by default?