2014-03-04 92 views
0

我想要得到所有Enum.valuesstring[]獲取枚舉值作爲字符串數組

我tryed使用

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

但是我怎麼投它作爲string[]

+0

你能更清楚嗎?你需要枚舉名稱或值(1,2,3)? –

+1

既然你已經'System.Array',看看http://stackoverflow.com/questions/1970738/convert-system-array-to-string –

+0

我需要枚舉名稱 – omriman12

回答

8

你只需要Enum.GetNames方法,Enum.GetValues給出的結果是EnumType而不是字符串。

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

我建議你只使用GetNames,不叫GetValues和它轉換爲字符串作爲註釋建議。

+0

是的,作品,thx – omriman12