C#字符串转枚举
定义一个表示方向的枚举:
public enum Position { [Description("上")] Up, [Description("下")] Down, [Description("左")] Left, [Description("右")] Right }
枚举转字符串:
string strPosition = Position.Left.ToString();
字符串转枚举:
Position position = (Position)Enum.Parse(typeof(Position), strPosition, true);