Iterate through an enumeration (Enum) in C#

In the C# language, the enum type (aka enumeration) is a user-defined value type used to represent a list of named integer constants. Enums are really useful when you want to generate dropdowns with well-known values (ex: a drop-down of weekdays, months, etc.), user-defined code flags.

Even though declaring enums is very straightforward, there are many things that are not clear about, and this is one of the topics that we will discuss. How, can we iterate through an Enum in C#?

As an example, I have created a list of enums for the weekdays:

Enum declaration.

Now, to get all the values of WeekDays, you can use the Enum.GetNames(typeof(type_of_enum)) then by using a foreach loop, you can navigate through all the Enum items.

Iteration of the Weekdays enum

When you run the project, this is the result that you will get.

Console result

If you want to learn more about .NET, you can check out my YouTube Channel.


Enjoyed this post? Subscribe to my YouTube channel for more great content. Your support is much appreciated. Thank you!


Check out my Udemy profile for more great content and exclusive learning resources! Thank you for your support.
Ervis Trupja - Udemy



Enjoyed this blog post? Share it with your friends and help spread the word! Don't keep all this knowledge to yourself.