Tuesday, 6 August 2013

Difference between || (Logical OR) and | (Conditional OR) operators in C#

Logical OR ||

If one condition is true compiler will return True without checking other conditions.
Ex:
if( A || B || C ) {}
If condition A is true without checking condition B compiler will return True.

Conditional OR |

Compiler will check for all the conditions.
Ex:
if( A | B | C ) {}
If condition A is true compiler  will check for condition B, and condition C if all conditions are True then only the compiler will return True otherwise it will return False.

No comments: