枚举
例如有
public enum AnimalEnum
{
Dog =12,
Cat = 10
}
{
Dog =12,
Cat = 10
}
Enum To String
AnimalEnum.Dog.ToString() == Dog
Enum To Int
int i = (int)AnimalEnum.Dog;
遍历枚举(反射 + Enum.GetNames())
字符串格式
Type type = typeof(AnimalEnum);string[] names = Enum.GetNames(type);
foreach (string str in names)
{
}
枚举格式
Array array = Enum.GetValues(typeof(AnimalEnum));
foreach (AnimalEnum ae in array)
{
}
Enum.Fotmat 格式化输出
public static string Format( Type enumType, Object value, string format )
format
d or D 十进制输出
x or X 十六进制输出
g or G 字符串格式输出
f or F 字符串格式输出
判断枚举是否定义
Enum.IsDefined(typeof(AnimalEnum),obj)
obj = int or string
int 枚举常熟
string 枚举字符串