1、定义枚举:
public enum TimeOfDay
{
Morning = 0,
Afternoon = 1,
Evening = 2
}
2、获取枚举值
1)写法1
TimeOfDay day = TimeOfDay.Morning;
var daytemp= (int)day;
2)写法2
TimeOfDay time2 = (TimeOfDay)Enum.Parse(typeof(TimeOfDay), "Afternoon", true);
var time2temp = (int)time2;