Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to enumerate an enum in C#?

Damian99Damian99 USAPosts: 116

I'm new to C# programming. Can someone please explain me with an example on how to enumerate an enum in C#?

Tagged:

Comments

  • DavidMDavidM USAPosts: 342
    edited January 2014

    Assume you have an enum as follows.
    public enum Car { Sports, Sedan, Hatchback, Classic }

    You can do the following.
    foreach (Car car in (Car[]) Enum.GetValues(typeof(Car))) { }

Sign In or Register to comment.