Operators and Expressions
Boolean Logical Operators
Logical negation operator !
bool passed = false;
Console.WriteLine(!passed); // output: True
Console.WriteLine(!true); // output: FalseLogical AND operator &
bool SecondOperand()
{
Console.WriteLine("Second operand is evaluated.");
return true;
}
bool a = false & SecondOperand();
Console.WriteLine(a);
// Output:
// Second operand is evaluated.
// False
bool b = true & SecondOperand();
Console.WriteLine(b);
// Output:
// Second operand is evaluated.
// TrueLogical OR operator |
x
y
x&y
x|y
Logical exclusive OR operator ^
Conditional logical AND operator &&
Conditional logical OR operator ||
Operator Precedence
null-coalescing operators (?? and ??=)
Last updated