.Net Goodness - Enumerating through an enumeration
The other day a friend of mine was asking if there was a simple way through reflection to list all the items in an enumeration. I figured I would share that answer here in case you need it too. Have a great day!
public enum DayOfWeek
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}
static void Main(string[] args)
{
Type dayOfWeekType = typeof(DayOfWeek);
foreach (DayOfWeek day in Enum.GetValues(dayOfWeekType))
{
Console.WriteLine(day.ToString());
}
}