Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在IF循环中设置枚举_C#_.net - Fatal编程技术网

C# 如何在IF循环中设置枚举

C# 如何在IF循环中设置枚举,c#,.net,C#,.net,我有一个名为“stateType”的枚举 在下面显示的函数“connection()”中,我只需要在 枚举“活动” 我将如何做到这一点,我需要在 if loop(if (this_event.variableData.Length >= 6)&& condition ) 我是这样做的 if (this_event.variableData.Length >= 6 && stateType.Active)

我有一个名为“stateType”的枚举

在下面显示的函数“connection()”中,我只需要在 枚举“活动”

我将如何做到这一点,我需要在

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\u clientStateType”的操作数D:\p\leaf.cs

state
null
。当您声明
stateType状态时,它的值为
null
。由于它是一个
enum
,您可以像使用
stateType.Active
一样使用它,而不是声明一个新变量。

您会遇到错误,因为您从未将状态变量分配给任何对象

如果我理解正确的话,你想要这样的东西:

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

您需要为state定义一些值

stateType state = something;

stateType state=stateType.Active
这是正确的。

您需要有一个场景,根据您提取的数据了解
状态类型是什么,只有在这之后,您才能对其进行比较


您的对象模型应该有一些东西可以指出它的
活动
非活动

您需要先分配状态,然后才能访问它。好的,您没有通过写入
状态类型状态
将任何内容分配给
状态
,因此错误很快得到解释。然而,我真的不明白你们想做什么…对不起,我编辑了我的问题,你们将根据哪些基础来决定活动状态。非常抱歉,有一些误解,如果它断开连接,它将设置为非活动。如果(this_event.variableData.Length>=6&&stateType.Active){Version=this_event.variableData[5],我会这样做.atr_value;}但它抛出的错误运算符“&&”不能应用于“bool”和“Spo.SPDlib.SPD.SPD_clientStateType”D:\P\leaf.csstateType.Active是一个枚举,您需要根据枚举的可能状态验证数据。这个_event.variableData.Length>=6这个就足够了,你能告诉我活动设置的依据吗?非常抱歉,有一些误解
if (this_event.variableData.Length >= 6 && stateType.Active == SPD.SPD_clientStateType.SPD_clientActive)
{
    Version = this_event.variableData[5].atr_value;
}
stateType state = something;