Loop through enums

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
 
J

John Saunders

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top