定义了颜色,当读取字符串时,想获得与之对应的枚举类型的值,可以用下面的代码实行public enum Color{RED = 1,GREEN = 2,BLUE = 3}static void Main(string[] args){string col = "BLUE";Color getType = (Color)Enum.Parse(typeof(Color),col)...
publicclassEnumExample{publicenumColor{RED,GREEN,BLUE;}publicstaticvoidmain(String[]args){// 根据名称获取值StringcolorName="RED";Colorcolor=Color.valueOf(colorName);System.out.println(color);// 输出:RED// 获取枚举常量的名称Colorcolor2=Color.GREEN;StringcolorName2=color2.name();System.out.printl...