Checking an ENUM

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all,

Is there a way to loop through a ENUM, like using a foreach loop?

I'd also like to know if you can do a 'Contains' or like method on an ENUM.

Thanks all,

JY
 
Is there a way to loop through a ENUM, like using a foreach loop?

foreach (YourEnum e in Enum.GetValues(typeof(YourEnum)))

I'd also like to know if you can do a 'Contains' or like method on an ENUM.

Enum.IsDefined()


Mattias
 
since an enumeration is (usually) integer based. you can also do
Enum.Parse(0), 1, 2, .... to get the values at the respective places
until an exception is thrown.
 

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

Enum TypeConverter 3
about enum 3
enum string value 3
Looping through multiple enumerations 1
enum type 3
Creating dropdown through enum 3
Check Flags Enum for Validity 15
Merge Info From Two Enums 1

Back
Top