如何根据数字获取到枚举类型。 枚举 :public enum content {
           衣服=1,
            裤子 = 2,
            鞋子 = 3,
            帽子 = 4,
        }传进来的参数是:1,2,3,4.

解决方案 »

  1.   

    直接转型就可以了,比如var a = (content)1;随便提一下,规范要求类,结构体等名字首字母大写哦:)
      

  2.   

    string temp=Enum.GetName(typeof(content), 1);//temp值为衣服
      

  3.   

                string str = "1,2,3,4";
                string[] result = str.Split(',');
                foreach (string s in result)
                {
                    Console.WriteLine(Enum.GetName(typeof(content), Convert.ToInt32(s)));
                }
      

  4.   

    if(content.value==1)
    {
      值是衣服
    }