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

omr*_*n12 1 c#

我想所有Enum.valuesstring[].

我试着用

Array mPriorityVals = Enum.GetValues(typeof(MPriority));
Run Code Online (Sandbox Code Playgroud)

但是我该怎么把它当作string[]

Sri*_*vel 12

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

string[] names = Enum.GetNames(typeof (MPriority));
Run Code Online (Sandbox Code Playgroud)

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