将Enum值作为字符串数组获取

时间:2014-03-04 12:08:07

标签: c#

我希望将所有Enum.values设为string[]

我尝试使用

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

但是如何将其转换为string[]

1 个答案:

答案 0 :(得分:10)

您只需要Enum.GetNames方法,Enum.GetValues将结果作为EnumType而不是字符串。

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

我建议您只使用GetNames,不要调用GetValues并按照评论中的建议将其转换为字符串。