问题11
得到枚举对象的对应值的下标
解决方案
Enum.Format 方法 [C#]
根据指定格式将指定枚举类型的指定值转换为其等效的字符串表示形式。
[C#]
public static string Format(
Type enumType,
object value,
string format
);
using System;
public class FormatTest {
enum Colors { Red, Green, Blue, Yellow };
public static void Main() {
Colors myColor = Colors.Blue;
Console.WriteLine("My favorite color is {0}", myColor);
Console.WriteLine("The value of my favorite color is {0}", Enum.Format(typeof(Colors), myColor, "d"));
Console.WriteLine("The hex value of my favorite color is {0}", Enum.Format(typeof(Colors), myColor, "x"));
}
}
[C#] public static string Format( Type enumType, object value, string format );
using System;
public class FormatTest {
enum Colors { Red, Green, Blue, Yellow };
public static void Main() {
Colors myColor = Colors.Blue;
Console.WriteLine("My favorite color is {0}", myColor);
Console.WriteLine("The value of my favorite color is {0}", Enum.Format(typeof(Colors), myColor, "d"));
Console.WriteLine("The hex value of my favorite color is {0}", Enum.Format(typeof(Colors), myColor, "x"));
}
}