简写为所有的bool YES或所有的bool NO? [英] Shorthand for all bools YES or all bools NO?

查看:312
本文介绍了简写为所有的bool YES或所有的bool NO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经常在我的code,我需要检查的bool的X量的状态是否都是真实的或全部的bool都是假的。所以,我做的:

Often in my code I need to check whether the state of x amount of bools are all true OR all bools are false. So I do:

BOOL first, second, third;
if((first && second && third) || (!first && !second && !third))
     //do something

作为一个懒惰的程序员,我想知道是否有这种类型的查询一些数学简写,而不必每次都输入了这件事?

Being a lazy programmer, I want to know if there is some mathematical shorthand for this kind of query, instead of having to type out this whole thing every time?

推荐答案

对于所有的bool同样是(配对)相等性测试的简写:

The shorthand for all bools the same is testing for (pairwise) equality:

(first==second && second==third)

当然,你可以扩展为任意数量的布尔值,其 N-1 平等会检查的加盟和的运营商。

Of course you can expand this to any number of booleans, having N-1 equality checks joined with the and operator.

这篇关于简写为所有的bool YES或所有的bool NO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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