我有一个带有一些值的简单枚举
Enum Status{
Available,
Taken,
Sold//and many more
}
我想检查状态是否介于可能的值之间(假设值的编写顺序是最低的是进程的开始,最后的是进程的最后步骤)< / p>
像
这样的东西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 :(得分:2)
您可以为枚举分配整数值,然后检查。
enum Status
{
Available = 1,
Taken = 2,
Sold = 3
//and many more
}
Status s1; // any value
if ((int)s1 <= 5 && (int)s1 >= 3)