How to list down all elements of a enum?

  • Thread starter Thread starter Kimelia
  • Start date Start date
K

Kimelia

For example, I have a public enum:

public enum MemberType
{
MEMBER_NORMAL = 0,
MEMBER_VIP = 1,
MEMBER_SUPERVIP = 2
}

Is it possible to use a foreach (or for) statement to list out all available
enum elements?

e.g.:

foreach (string s in MemberType) ?????

Thanks
 
For example, I have a public enum:

public enum MemberType
{
MEMBER_NORMAL = 0,
MEMBER_VIP = 1,
MEMBER_SUPERVIP = 2
}

Is it possible to use a foreach (or for) statement to list out all available
enum elements?

If you just want the names:

string[] names = Enum.GetNames(typeof(MemberType));
 
The static GetNames() method on the Enum class should work for this.
 

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
Merge Info From Two Enums 1
number of values in enum 2
Get element in List<T> 5
Enum Extentions 7
Iterate through enum of system.drawing.color 5
Enum to ListBox 2

Back
Top