C# 逻辑运算符
逻辑非运算符:!
如果操作数的计算结果为 false
,它生成 true
;如果操作数的计算结果为 true
,它生成 false.
对结果取反
=================================
逻辑与运算符:&
如果 x
和 y
的计算结果都为 true
,则 x & y
的结果为 true
。 否则,结果为 false
。
即任意有一个操作数为false,结果为false。如果全是false结果也为false;只有全是true的情况下,结果才为true
=================================
逻辑或运算符:|
当且仅当两个操作数均为 false时,结果才为 false。
即任意有一个操作数为true,结果就为true。
=================================
逻辑异或运算符:^
如果 x
计算结果为 true且 y
计算结果为 false,或者 x
计算结果为 false且 y
计算结果为 true,那么 x ^ y
的结果为 true。 否则,结果为 false。
即任意一个操作数为true的情况下,结果为true;如果操作数全为true,或者全为false,那么结果为false;