0
0
C Sharp (C#)programming~15 mins

Enum declaration syntax in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Enum declaration syntax
📖 Scenario: Imagine you are creating a simple program to manage the days of the week. You want to use an enum to represent the days so your code is clear and easy to read.
🎯 Goal: You will create an enum named DaysOfWeek with all seven days as its members. Then, you will print one of the days to see how enums work in C#.
📋 What You'll Learn
Create an enum called DaysOfWeek with members: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
Create a variable called today of type DaysOfWeek and set it to DaysOfWeek.Wednesday
Print the value of today to the console
💡 Why This Matters
🌍 Real World
Enums are used to represent fixed sets of related constants, like days, months, directions, or states in a program.
💼 Career
Understanding enums helps you write clearer and safer code, which is important in many software development jobs.
Progress0 / 4 steps
1
Create the enum DaysOfWeek
Write an enum declaration named DaysOfWeek with these members exactly: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
C Sharp (C#)
Need a hint?

Use the enum keyword followed by the name DaysOfWeek. Inside curly braces, list all days separated by commas.

2
Create a variable today of type DaysOfWeek
Create a variable called today of type DaysOfWeek and set it to DaysOfWeek.Wednesday.
C Sharp (C#)
Need a hint?

Use the syntax: DaysOfWeek today = DaysOfWeek.Wednesday;

3
Print the value of today
Write a Console.WriteLine statement to print the value of the variable today.
C Sharp (C#)
Need a hint?

Use Console.WriteLine(today); to print the enum value.

4
Run the program to see the output
Run the program and observe the output. It should print Wednesday.
C Sharp (C#)
Need a hint?

The program should print Wednesday exactly.