2017-03-08 70 views
-1

布尔表达式我有几个值的简单枚举涉及枚举和Int

Enum Status{ 
Available, 
Taken, 
Sold//and many more 
} 

我要检查其状态是否在可能的值(假设值写入这样的次序之间的某处最低的是一个进程的开始,而最后的是过程的最后步骤)

喜欢的东西

Status s1;//Some value 
if(s1<5 && s1>3) 
//The value is one of the enum values in those range 
//(for example the job has already been accepted, but has still not been 
//shipped) 

这可能吗?

感谢。

+0

只需将状态转换为int并执行检查:(int)s1 – bcl

+0

有人删除此问题,我无法弄清楚如何正确搜索它。 – master2080

+0

您可以自己删除它。编辑旁边有一个按钮。我们不会为你做。 –

回答

1

您可以将整数值分配给您的枚举,然后检查。

enum Status 
{ 
    Available = 1, 
    Taken = 2, 
    Sold = 3 
    //and many more 
} 

Status s1; // any value 
if ((int)s1 <= 5 && (int)s1 >= 3) 
+0

那么因为默认情况下,枚举是整数,我猜不会分配数字已经把它们按顺序,这是正确的吗? – master2080

+0

@ master2080正确,从索引0开始。 –