逻辑(二进制)运算符Logical (binary) operators

支持在 bool 类型的两个值之间使用以下逻辑运算符:The following logical operators are supported between two values of the bool type:

备注

这些逻辑运算符有时称为布尔运算符,有时称为二元运算符。These logical operators are sometimes referred-to as Boolean operators, and sometimes as binary operators. 这些名称都是同义词。The names are all synonyms.

操作员名称Operator name 语法Syntax 含义Meaning
相等Equality == 如果两个操作数均非 null 且彼此相等,则生成 trueYields true if both operands are non-null and equal to each other. 否则为 falseOtherwise, false.
不相等Inequality != 如果两个操作数不相等或至少有一个为 null,则生成 trueYields true if either one (or both) of the operands are null, or they are not equal to each other. 否则为 trueOtherwise, true.
逻辑与Logical and and 如果两个操作数都为 true,则生成 trueYields true if both operands are true.
逻辑或Logical or or 如果其中一个操作数是 true,则无论其他操作数如何,都将生成 trueYields true if one of the operands is true, regardless of the other operand.

备注

考虑到布尔 null 值 bool(null) 的行为,我们可以说:两个布尔 null 值既不相等也不不相等(换句话说,bool(null) == bool(null)bool(null) != bool(null) 都生成值 false)。Due to the behavior of the Boolean null value bool(null), two Boolean null values are neither equal nor non-equal (in other words, bool(null) == bool(null) and bool(null) != bool(null) both yield the value false).

另一方面,and/or 将 null 值视为等效于 false,因此 bool(null) or truetruebool(null) and truefalseOn the other hand, and/or treat the null value as equivalent to false, so bool(null) or true is true, and bool(null) and true is false.