Skip to main content

How to enumerate an enum

In the last post I described how you can cast an c# enumeration. In my second post I show how you can enumerate an enumeration. It is very simple. Let’s say we have an enum:

public enum CarManufacturer
{
    BMW,
    Audi,
    VW
}

Now you can easily get the names by:

foreach (string s in Enum.GetNames(typeof(CarManufacturer)))
{
  System.Console.WriteLine(s);
}

Daniel Zuidinga

.NET-Developer, Dipl.-Ing., Borussia Dortmund Supporter

Leave a Reply

Your email address will not be published. Required fields are marked *