C# 遍历枚举类

framework 4.0 环境下

方法

定义枚举类

判断枚举类中是否存在,若存在则输出

例子:

Defined.QrCode.QrCodeType type;//枚举类

if (!Enum.TryParse<Defined.QrCode.QrCodeType>( aa,out type))
{
     context.Response.Write("枚举类不存在");
     return null;
}

  framework 4.0 以下版本

定义哈希表或者list集合,然后验证集合中是否存在要验证的数值

List<string> lst=new List<string>();

foreach (testenum item in Enum.GetValues(typeof(testenum)))
{
     lst.add(item);
}

if(lst.contains("aa"))
{
    Messagebox.Show("包含aa")
}

posted on 2014-10-29 10:04  黎木  阅读(945)  评论(0编辑  收藏  举报

导航