C# OR Operator

And operator is "&&", or operator is "||". They are used in condition statements.

int i=15;
if (i % 3 == 0 && i % 5 == 0) {...}
if (i % 8 == 0 || i % 3 == 0) {...}

If the first statement is true, then the second statement will not be checked.
int i = 8;
int j = 9;
if (i % 2 == 0 || j % 3 ==0 ) //j % 3 == 0 is not checked, because i % 2 == 0 is true
{...}

Operator "|" will check all statements.
int i = 8;
int j = 9;
if (i % 2 == 0 | j % 3 ==0 ) //j % 3 == 0 is checked, even i % 2 == 0 is true
{...}


endmemo.com © 2024  | Terms of Use | Privacy | Home