c sharp operators

  • Thread starter Thread starter Aaron
  • Start date Start date
|| and && are logical operators

they evaluate into this and that, or , this or that..


the single ones are bitwise operators

if i have the bit pattern 1111 and 1010 if i do 1111 | 1010 it will or each
bit with its corresponding bit in the other one resulting in 1111 if i do
1111 & 1010 it will result in 1010.
 
Consider

int a = 0;
int b = 0;

if((a == 1) && (b = 1) == 0){}

&& instead of & means, that if a != 1, IF returns false without ever
checking the second statement, whereas with
& both statements would be calculated

&& -> a = 0, b = 0
& -> a = 0, b = 1

Same with || and |. If the first statement is true || will ignore the
second statement, whereas | will check both.

So, for || and && you run the risk that initiations happening in the
second statements may or may not get done, but you will also benefit from
not having to done lengthy initiations if doesn't need to be done since
the if block would or wouldn't get executed anyway.
 
Back
Top