Avatar ·

How to iterate over all values of an enum in C#?

Hello everyone! I'm new to C# and I've encountered a problem: I have an enum that contains several constants, for example, days of the week or order statuses. I need to loop through all possible values of this enum and perform some action with them, such as printing them to the console or adding them to a dropdown list. I tried using a regular `for` loop with indices, but it doesn't work because an enum is not an array. Additionally, the values in an enum may not be sequential (for example, with explicitly assigned numbers). Here's an example of my code, which is obviously incorrect: ```csharp enum DaysOfWeek { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } // My attempt (doesn't work) for (int i =