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));
 
Back
Top