[英]How to use multiple AND operators?
I have 6x List<int>
: PL1
, PL2
, PL3
, PL4
, PL5
and PL6
and I want to call a function IF ALL of those Lists don't have a count of 6.我有 6x
List<int>
: PL1
、 PL2
、 PL3
、 PL4
、 PL5
和PL6
,如果所有这些列表的计数都不为 6,我想调用 function 。
Example:例子:
All lists except PL4
have a count of 6 -> The function will execute.除
PL4
之外的所有列表的计数均为 6 -> function 将执行。
All lists have a count of 6 -> The function will not execute.所有列表的计数均为 6 -> function 将不会执行。
I'm trying to achieve this with:我试图通过以下方式实现这一目标:
if (PL6.Count != 6 && PL5.Count != 6 && PL4.Count != 6 && PL3.Count != 6 && PL2.Count != 6 && PL1.Count != 6)
{
Function();
}
.. which is not working. ..这是行不通的。 How do I get it to work?
我如何让它工作? I tried
&
, &&
, |
我试过
&
, &&
, |
and ||
和
||
in the statement.在声明中。
It sounds like the behaviour you're trying to capture is "execute the function if any of the lists don't have a count of 6".听起来您要捕获的行为是“如果任何列表的计数不为 6,则执行 function”。 If this is your intent then you'll want the OR operator (
||
):如果这是您的意图,那么您将需要 OR 运算符(
||
):
if (PL6.Count != 6 || PL5.Count != 6 || PL4.Count != 6 || PL3.Count != 6 || PL2.Count != 6 || PL1.Count != 6)
{
Function();
}
Alternatively you could write this as:或者,您可以将其写为:
if (!(PL6.Count == 6 && PL5.Count == 6 && PL4.Count == 6 && PL3.Count == 6 && PL2.Count == 6 && PL1.Count == 6))
{
Function();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.