Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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# 如何使用多个AND运算符?_C#_List_If Statement_Console Application_Logical Operators - Fatal编程技术网

C# 如何使用多个AND运算符?

C# 如何使用多个AND运算符?,c#,list,if-statement,console-application,logical-operators,C#,List,If Statement,Console Application,Logical Operators,我有6xList:PL1,PL2,PL3,PL4,PL5和PL6,如果所有这些列表的计数都不为6,我想调用一个函数 例如: 除了PL4之外的所有列表的计数都为6->该函数将执行 所有列表的计数均为6->该函数将不执行 我正试图通过以下方式实现这一目标: if (PL6.Count != 6 && PL5.Count != 6 && PL4.Count != 6 && PL3.Count != 6 && PL2.Count != 6

我有6x
List
PL1
PL2
PL3
PL4
PL5
PL6
,如果所有这些列表的计数都不为6,我想调用一个函数

例如:

除了
PL4
之外的所有列表的计数都为6->该函数将执行

所有列表的计数均为6->该函数将不执行

我正试图通过以下方式实现这一目标:

if (PL6.Count != 6 && PL5.Count != 6 && PL4.Count != 6 && PL3.Count != 6 && PL2.Count != 6 && PL1.Count != 6)
{
     Function();
}

。。这是行不通的。我如何让它工作?我在语句中尝试了
&
&
|
|

听起来您试图捕获的行为是“如果任何列表的计数不为6,则执行函数”。如果这是您的意图,那么您需要OR运算符(
|
):

或者,您可以这样写:

if (!(PL6.Count == 6 && PL5.Count == 6 && PL4.Count == 6 && PL3.Count == 6 && PL2.Count == 6 && PL1.Count == 6))
{
     Function();
}

上面的代码对您无效吗?还是你在寻找一种更干净的方法?你必须告诉我们你想要什么听起来你想用逻辑OR代替AND。或者否定整个操作链的结果。如果我这里的方法不起作用,我想知道如何才能实现我所写的。或者也不起作用。我试过
&
&
|
。你的选择帮了我的忙!非常感谢。我需要更多地使用逻辑运算符,有时对我来说仍然很困惑。
if (!(PL6.Count == 6 && PL5.Count == 6 && PL4.Count == 6 && PL3.Count == 6 && PL2.Count == 6 && PL1.Count == 6))
{
     Function();
}