我认为这个问题的类型需要一些代码:如何得到一个枚举的整数值,当我只有枚举
private TypeValues GetEnumValues(Type enumType, string description)
{
TypeValues wtv = new TypeValues();
wtv.TypeValueDescription = description;
List<string> values = Enum.GetNames(enumType).ToList();
foreach (string v in values)
{
//how to get the integer value of the enum value 'v' ?????
wtv.TypeValues.Add(new TypeValue() { Code = v, Description = v });
}
return wtv;
}
这样称呼它:
GetEnumValues(typeof(AanhefType), "some name");
在GetEnumValues
函数我有枚举的值。所以我迭代的值,我想获得该枚举值的整数值也。
所以我的价值观是“红”,“绿”,我也希望得到0和1
,当我在我的函数有枚举,我可以从字符串和投枚举值它的枚举,然后将其转换为int,但在这种情况下,我没有枚举本身,但只有枚举的类型。
我试着将实际枚举作为参数传入,但我不允许将枚举作为参数传递。
所以现在我卡住.....
这个工程!奇怪的是,在直接窗口中尝试了一些代码,并且也没有显示出int值:(int)Enum.Parse(enumType,v)显示我'De Heer',它是字符串' v”。但是在运行代码时,它会显示一个int。怪异的...... – Michel 2011-06-15 07:31:40