提问
如何获取枚举名称
回答
using System;
public class GetNameTest {
enum Colors { Red, Green, Blue, Yellow };
enum Styles { Plaid, Striped, Tartan, Corduroy };
public static void Main() {
Console.WriteLine("The 4th value of the Colors Enum is {0}", Enum.GetName(typeof(Colors), 3));
Console.WriteLine("The 4th value of the Styles Enum is {0}", Enum.GetName(typeof(Styles), 3));
}
}
// The example displays the following output:
// The 4th value of the Colors Enum is Yellow
// The 4th value of the Styles Enum is Corduroy
参考
https://learn.microsoft.com/zh-cn/dotnet/api/system.enum.getname?view=net-7.0
标签:Styles,enum,Enum,Colors,value,获取,枚举,4th,名称 From: https://www.cnblogs.com/wuhailong/p/17736009.html