C#如果不是(this)或(this)或(this)-多条件IF/OR [英] C# If not (this) Or (this) or (this) - Multiple condition IF/OR

查看:61
本文介绍了C#如果不是(this)或(this)或(this)-多条件IF/OR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似的情况:

 if (!(InRange1 || InRange2 || InRange3))
{
//Do Something
}

每个InRange变量都是布尔值.

Each of the InRange Variables are boolean.

所需的行为是,如果这些值中的任何一个为False,我都想做点什么,但它不能那样工作.在触发事件之前,所有值都必须为false.

The desired behavior is if anyone of those values is False I want to do something, but it is not working that way. All of the values have to be false before the event is triggered.

是否需要写为

if (!InRange1 || !InRange2 || !InRange3)
{
//do something
}

而且,无论哪种情况,我都很好奇为什么原始语句不起作用.

And, in either case I'm curious why the original statement doesn't work.

推荐答案

您可以使用迪摩根定律.

您拥有的等同于NOR.!(A | B | C)等同于!A&!B&!C 根据摩根大通定律.

What you have is equivalent to NOR. !(A | B | C) is equivalent to !A & !B & !C by DeMorgan's Law.

您想要的是NAND,所以!(A& B&& C).这与您要查找的内容完全相同-!A |!B |!C .

What you want is NAND, so !(A && B && C). This is exactly equivalent to what you're looking for - !A | !B | !C.

这篇关于C#如果不是(this)或(this)或(this)-多条件IF/OR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆