Loop through enums

  • Thread starter Thread starter Syd
  • Start date Start date
S

Syd

Has anybody ever figured a way to automatically loop through an enum,
as if it were a collection? Here's an example of an enum we're using:

public enum TaskType
{
TaskRange = 1,
TaskSort = 2,
TaskScope = 3
}

And what we'd like to loop through each item in a for-each loop, since
we don't always know how many enums there are (without a human being
checking)...

TIA!
Syd
 
Syd said:
Has anybody ever figured a way to automatically loop through an enum,
as if it were a collection? Here's an example of an enum we're using:

public enum TaskType
{
TaskRange = 1,
TaskSort = 2,
TaskScope = 3
}

And what we'd like to loop through each item in a for-each loop, since
we don't always know how many enums there are (without a human being
checking)...

Take a look at the System.Enum class. In particular, System.Enum.GetNames
might help you out.
 
Back
Top