.NET日常之枚举

枚举类型默认修饰符为public,且不能显式使用修饰符

enum Demo
{
       red = 0,
       green = 1,
       yellow = 2,
       blue = 3
}
枚举类型转换为对应的数值

Convert.ToInt32(Demo.blue);
(int)Demo.blue;
枚举转换为字符串
Demo.blue.ToString();
 
 
 数值转换为对应的字符串 
 

Enum.GetName(new Demo().GetType(), 1);
将字符串转换为枚举类型

(Demo)Enum.Parse(typeof(Demo), "red");







猜你喜欢

转载自blog.csdn.net/PLF_1994/article/details/78831108
今日推荐