【发布时间】:2010-10-30 21:55:38
【问题描述】:
我有一个名为Questions(复数)的课程。在这个类中有一个名为Question(单数)的枚举,看起来像这样。
public enum Question
{
Role = 2,
ProjectFunding = 3,
TotalEmployee = 4,
NumberOfServers = 5,
TopBusinessConcern = 6
}
在Questions 类中,我有一个get(int foo) 函数,它为foo 返回一个Questions 对象。有没有一种简单的方法可以从枚举中获取整数值,以便我可以执行类似 Questions.Get(Question.Role) 的操作?
【问题讨论】:
-
我知道我迟到了,但是不要将你的方法定义为
get(int foo),你可以将它定义为get(Question foo),然后在方法中进行转换,你可以调用你的方法作为Questions.Get(Question.Role) -
试试这个:int int_Choose = (int) Question.Role;