字符串和枚举相互转换

定义一个枚举:
  private enum myType
    {
        a = 1,
        b = 2,
        c = 3,
        lao = 4
    }

//字符串转枚举
 bool TryParse = Enum.IsDefined(typeof(myType), "a");
        if (TryParse)
        {
            object m = Enum.Parse(typeof(myType), "c");
            myType t = (myType)m;
        }

 

//枚举转字符串
myType.a.ToString();

 

posted @ 2014-03-28 16:13  JasonGu0  阅读(1104)  评论(0编辑  收藏  举报