Exploring Enums and Structs
Discover enums and structs to represent fixed sets of values and lightweight objects.
Exploring Enums and Structs is a free C# Academy lesson on CoddyKit. This is lesson 4 of 6. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C# Academy learning path, and your progress syncs across the web and the CoddyKit app. The C# Academy course includes 6 lessons in total.
Exploring Enums and Structs
Welcome to the next lesson! In this lesson, you’ll learn about enums and structs in C#, their purposes, and how to use them to organize your code and manage data effectively. Let’s get started!

What is an Enum?
An enum (short for enumeration) is a value type that defines a set of named constants. It is used to make code more readable and manage related values.
Example: Days of the week, months, or status codes can be represented as enums.
Why Use Enums
What is an Enum?
An enum (short for enumeration) is a value type that defines a set of named constants. It is used to make code more readable and manage related values.
Example: Days of the week, months, or status codes can be represented as enums.
Key Point: Enums provide meaningful names for numeric values, improving code clarity.
<h2>Defining and Using Enums</h2>
<p>To define an enum, use the <code>enum</code> keyword. Example:</p>
What is a Struct?
A struct is a value type that groups related variables into a single type. It is used for lightweight objects that do not require inheritance.
Example: Representing a point in a 2D space with X and Y coordinates.
Defining and Using Structs
To define a struct, use the struct keyword. Example:
Tip: Use structs for small, immutable data types that represent a single value or concept.
using System;
struct Point {
public int X;
public int Y;
public void Display() {
Console.WriteLine($"Point: ({X}, {Y})");
}
}
class Program {
static void Main() {
Point point = new Point { X = 10, Y = 20 };
point.Display(); // Outputs: Point: (10, 20)
}
}
Enums with Explicit Values
You can assign specific values to enum members. Example:
Key Point: Explicit values make enums useful for mapping to constants like HTTP status codes.
using System;
enum HttpStatusCode {
OK = 200,
BadRequest = 400,
NotFound = 404,
InternalServerError = 500
}
class Program {
static void Main() {
HttpStatusCode code = HttpStatusCode.OK;
Console.WriteLine($"Code: {(int)code}, Status: {code}"); // Outputs: Code: 200, Status: OK
}
}
Practice Challenge
Create an enum OrderStatus with values Pending, Processing, Shipped, and Delivered. Create a struct Order that includes an ID and status. Example:
using System;
enum OrderStatus {
Pending,
Processing,
Shipped,
Delivered
}
struct Order {
public int ID;
public OrderStatus Status;
public void Display() {
Console.WriteLine($"Order ID: {ID}, Status: {Status}");
}
}
class Program {
static void Main() {
Order order = new Order { ID = 1, Status = OrderStatus.Processing };
order.Display(); // Outputs: Order ID: 1, Status: Processing
}
}
Best Practices for Enums and Structs
Here are some best practices:
- Use enums for related constants that improve code readability.
- Use structs for lightweight, immutable objects with no inheritance.
- Avoid adding complex methods or logic to structs to maintain their simplicity.
Tip: Combine enums and structs to represent real-world entities effectively.
Great Job!
Congratulations! You’ve learned how to use enums and structs to organize and manage data effectively in C#. In the next lesson, we’ll explore delegates and events to handle asynchronous and event-driven programming. Let’s keep coding!

Learn C# with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 93
- Lessons
- 346
Frequently Asked Questions
Is the “Exploring Enums and Structs” lesson free?
Yes — the full text of “Exploring Enums and Structs” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C# Academy course, upgrade to CoddyKit PRO. The C# Academy course includes 6 lessons in total.
What will I learn in “Exploring Enums and Structs”?
Discover enums and structs to represent fixed sets of values and lightweight objects. You practise C# Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C# Academy?
No prior experience is required. C# Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 6.
How long does the “Exploring Enums and Structs” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C# Academy lesson?
Yes. Every C# Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Introduction to Interfaces
- Abstract Classes
- Static Members and Methods
- Exploring Enums and Structs
- Delegates and Events
- Working with Collections: Lists, Dictionaries, and Queues