Knowledge Management Banner

Knowledge Management Banner

C# : if loop single operator , double operator : Part 18

  • Using single operator will check all consition if first one is true.
  • Using double operator in if loop will not check other consition if first one or previous one is true

  •  if (a == 1 | a == 2)  
     {  
        //Do something  
     }  
    
  • In above code if loop, even if the first condition is true the second condition will also be checked

  •  if (a == 1 || a == 2)  
     {  
        //Do something  
     }  
    

  • In above code if loop, if the first condition is true the second condition will not be checked

No comments

Powered by Blogger.