Listing the values contained in an Enumeration C#
The following code, shows how to list the values withing an enumeration.
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());
}
}
No comments:
Post a Comment