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);
posted @ 2019-11-05 14:16  懵咚  阅读(5373)  评论(0编辑  收藏  举报