2017-03-08 76 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開始。 –