2011-02-03 57 views
-1

我有一個名爲「stateType」的枚舉。如何在IF循環中設置枚舉

enum stateType : int 
    { 
    Unknown = 0, 
    Active = 1, 
    Inactive = 2 
    } 

在我的功能「連接()」顯示下面我只需要在 枚舉「活動」時,顯示的版本。

static private void connction() 
{ 
    string hostName = this_event.variableData[0].atr_value; 
    string policyGuid = this_event.variableData[1].atr_value; 
    string policyVersion = this_event.variableData[2].atr_value; 
    string formatVersion = this_event.variableData[3].atr_value; 
    string enabled = this_event.variableData[4].atr_value; 
    string Version = "0.0.0.0"; 
    if (this_event.variableData.Length >= 6) 
    { 
     Version = this_event.variableData[5].atr_value; 
    } 
} 

我將如何做到這一點,我需要在

if loop(if (this_event.variableData.Length >= 6)&& condition) 

我做了這樣

  if (this_event.variableData.Length >= 6 && stateType.Active) 
           { 
            Version = this_event.variableData[5].atr_value; 
           } 

我得到來設定條件錯誤操作「& &」不能應用於'bool'和'Spo.SPDlib.SPD.SPD_clientStateType'類型的操作數D:\ P \ leaf.cs

+1

您需要分配狀態,然後才能訪問它。 – 2011-02-03 10:54:43

+0

好吧,您沒有通過寫入stateType狀態來將任何內容分配給`state`,因此很快就會解釋錯誤。但是,我不太明白你想要做什麼... – 2011-02-03 10:55:28

+0

對不起,我已編輯我的問題 – peter 2011-02-03 11:02:34

回答

0

statenull。當你聲明你的stateType state時,它的值爲null。因爲它是enum,您可以像stateType.Active那樣使用它,而不是聲明新的變量。

1

由於您從未將狀態變量分配給任何事物,因此您會遇到錯誤。

如果我理解正確的話,你想是這樣的:

if (this_event.variableData.Length >= 6 && stateType.Active == SPD.SPD_clientStateType.SPD_clientActive) 
{ 
    Version = this_event.variableData[5].atr_value; 
} 
0

您需要定義狀態

stateType state = something; 
0

stateType state = stateType.Active;這是正確的一些價值。

1

您需要知道StateType基於您拉起的數據的場景,只有在此之後您才能比較它。

對象模型應該有一些東西,會指出,其ActiveInactive