Notifications
Clear all

Enumerate an enum in C#  

   RSS

2

The following code produces below compilation error,

'WorkDay' is a 'type' but is used like a 'variable' -- fails on the foreach statement

public enum WorkDay
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday
}

foreach (WorkDay day in WorkDay)
{
DoSomething(day);
}
This topic was modified 10 months ago by chapr89
This topic was modified 10 months ago 2 times by Raja
Topic Tags
1 Answer
2
foreach (WorkDay day in (WorkDay[]) Enum.GetValues(typeof(WorkDay)))
{
DoSomething(day);
}
Share:
Share this
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •