Skip to content

enum definition

Context: Define an enum using the enum keyword. By default, the first member has value 0, and each subsequent member increments by 1.

[access modifier] enum EnumName
{
Member1,
Member2,
Member3
}
public enum DaysOfWeek
{
Sunday, // 0
Monday, // 1
Tuesday, // 2
Wednesday, // 3
Thursday, // 4
Friday, // 5
Saturday // 6
}

Order status: Define OrderStatus enum with Pending, Processing, Shipped, Delivered, Cancelled to make code self‑documenting.

Example: In e‑commerce applications, enums are often used for state machines. The State pattern can be combined with enums.