


In the following example, the right-hand operand of the & operator is a method call, which is performed regardless of the value of the left-hand operand: bool SecondOperand()Ĭonsole.WriteLine("Second operand is evaluated.") The & operator evaluates both operands even if the left-hand operand evaluates to false, so that the operation result is false regardless of the value of the right-hand operand. The result of x & y is true if both x and y evaluate to true. The & operator computes the logical AND of its operands. That is, it produces true, if the operand evaluates to false, and false, if the operand evaluates to true: bool passed = false Ĭonsole.WriteLine(!passed) // output: TrueĬonsole.WriteLine(!true) // output: Falseīeginning with C# 8.0, the unary postfix ! operator is the null-forgiving operator. The unary prefix ! operator computes logical negation of its operand. For more information, see Bitwise and shift operators. Those operators evaluate the right-hand operand only if it's necessary.įor operands of the integral numeric types, the &, |, and ^ operators perform bitwise logical operations. Binary & (conditional logical AND) and || (conditional logical OR) operators.Those operators always evaluate both operands. Binary & (logical AND), | (logical OR), and ^ (logical exclusive OR) operators.The following operators perform logical operations with bool operands:
