开发者

How to set enumeration in IF loop

I have an enumeration named "stateType".

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

In my function "connection()" showed below i need to display version only at the time of enumeration "Active".

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;
    }
}

How will i do that, i need to set a condition in the

if loop(if (this_event.v开发者_StackOverflow社区ariableData.Length >= 6)&& condition )

I did this way

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

i am getting error Operator '&&' cannot be applied to operands of type 'bool' and 'Spo.SPDlib.SPD.SPD_clientStateType' D:\P\leaf.cs


You're getting error becouse you've never assigned state variable to anything.

If i understand you correctly you want something like this:

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


You need to have a scenario of knowing what the StateType is based on the data you pull up, only after that will you be able to compare it.

Your object model should have something which will point out that its Active or Inactive


state is null. When you declare your stateType state, it is of null value. As it's an enum, you could use it like stateType.Active for example, rather than declaring a new variable.


You need to define some value for state

stateType state = something;


stateType state = stateType.Active; This is correct.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜