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
Remember, if you want me to respond to your comment, then you need to use a Google/OpenID account to leave the comment.