刚刚遇到的问难:
很简单的方法,记下以备以后查看方便
public enum Colcr1
{
red,
yellow
}
public enum Colcr2
{
green,
bule
}
string str;string a="111";
public AA()
{
if(Enum.IsDefinde(typeof(Color1),str))//判断这个枚举里是否有和这个字符串相匹配的值
{
a=((Color1)Enum.Parse(typeof(Color1), str)).toString();//把这个字符串转换成枚举,再把枚举转化为字符串
}
else if(Enum.IsDefinde(typeof(Color2),str))
{
a=((Color2)Enum.Parse(typeof(Color2), str)).toString();
}
Console.WriterLine(a);
}
如果str赋值是两个枚举中任意一个的话,那么就会输出相应的str
但是如果没有的话就会输出111
噢哈哈哈哈