Skip to content

Enums

Context: An enum defines a set of named constants. Enums make code more readable and type‑safe.

public enum Color
{
Red,
Green,
Blue
}

HTTP status codes: Define an enum for HTTP status codes (200 OK, 404 NotFound) to avoid magic numbers.

Example: In ASP.NET Core, HttpStatusCode is an enum. Also DayOfWeek is a built‑in enum.