2

I want to get all Enum.values as string[].

I tryed using

Array mPriorityVals = Enum.GetValues(typeof(MPriority));

But how do I cast it as string[]?

2
  • Can you be more clear? You need enum names or values (1,2,3)? Commented Mar 4, 2014 at 12:09
  • 1
    Since you have already System.Array, take a look at stackoverflow.com/questions/1970738/… Commented Mar 4, 2014 at 12:10

1 Answer 1

14

You just need Enum.GetNames method, Enum.GetValues gives the result as EnumType rather than string.

string[] names = Enum.GetNames(typeof (MPriority));

I suggest you to just use GetNames, don't call GetValues and cast it to string as suggested in comment.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.