Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Enum values as string array [duplicate]

Tags:

c#

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[]?

like image 638
omriman12 Avatar asked Dec 02 '25 09:12

omriman12


1 Answers

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.

like image 62
Sriram Sakthivel Avatar answered Dec 04 '25 23:12

Sriram Sakthivel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!