Logical operators : Logical Relational Operators : Operator C# Examples


C# Examples » Operator » Logical Relational Operators »

 

Logical operators








Operator
Meaning


&
AND


|
OR


^
XOR (exclusive OR)


||
Short-circuit OR


&&
Short-circuit AND


!
NOT






p
Q
p & q
p | q
p ^ q
!p


False
False
False
False
False
True


True
False
False
True
True
False


False
True
False
True
True
True


True
True
True
True
False
False







    
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");  
    }        
}
    
   
  
   



Output

a = 8
a = 14
a = 6
a = -13


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Operator
» Logical Relational Operators