从枚举中检索整数值 [英] Retrieving integer values from an enum
本文介绍了从枚举中检索整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经定义了一个枚举并尝试按如下方式检索它
I have defined an enum and tried to retrieve it as follows
class Demo
{
enum hello
{
one=1,
two
}
public static void Main()
{
Console.WriteLine(hello.one);
Console.ReadLine();
}
}
现在,如何检索整数值枚举中的1?
Now, how do i retrieve the integer value "1" from the enum ?
推荐答案
HI
请访问此链接
< a href =http://stackoverflow.com/questions/943398/get-int-value-from-enum> http://stackoverflow.com/questions/943398/get-int-value-from-enum [ ^ ]
尝试使用GetHashCode mehtod如下
try to use GetHashCode mehtod like below
Console.WriteLine(hello.one.GetHasCode());
Console.WriteLine((int)hello.one);
快乐编码!
:)
Happy Coding!
:)
这篇关于从枚举中检索整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文