.NET之枚举

假如有以下枚举:

public enum eState
{
    Pass = 1,
    Fail = -1,
    Invalid = 0,
}

1. 取出枚举的列表

public IEnumerable<eRoomState> RoomStateList
{
       get
       {
             return Enum.GetValues(typeof(eRoomState)).Cast<eRoomState>();
        }
}

  

2. 根据KEY获取枚举的VALUE值

int state = (int)Enum.Parse(typeof(eState), "Pass");
原文地址:https://www.cnblogs.com/wantoo/p/4658674.html