Logical operators : Logical Relational Operators « Operator « C# / CSharp Tutorial






OperatorMeaning
&AND
|OR
^XOR (exclusive OR)
||Short-circuit OR
&&Short-circuit AND
!NOT


pQp & qp | qp ^ q!p
FalseFalseFalseFalseFalseTrue
TrueFalseFalseTrueTrueFalse
FalseTrueFalseTrueTrueTrue
TrueTrueTrueTrueFalseFalse


using System; 
 
class Example {    
  public static void Main() {    
     bool b1, b2; 
 
    b1 = true; 
    b2 = false; 
    if(b1 & b2) 
        Console.WriteLine("(b1 & b2) is true"); 
    if(!(b1 & b2)) 
        Console.WriteLine("!(b1 & b2) is true"); 
    if(b1 | b2) 
        Console.WriteLine("b1 | b2 is true"); 
    if(b1 ^ b2) 
        Console.WriteLine("b1 ^ b2 is true"); 
  }    
}
a = 8
a = 14
a = 6
a = -13








3.6.Logical Relational Operators
3.6.1.Relational Operators
3.6.2.Logical operators
3.6.3.false expressions for operators: ==, > and <
3.6.4.true expressions for operators: !=, >, <
3.6.5.Boolean logical AND operator
3.6.6.Boolean logical OR operator
3.6.7.Boolean logical NOT operator
3.6.8.Logical operators with an if statement
3.6.9.List of Boolean Operators