Possible Duplicate:
What is the difference between logical and conditional AND, OR in C#?
What is the difference between Bitwise AND & and Logical AND &&??
&
modifies integers with bitwise operations, ie. 1000 & 1001 = 1000
, &&
compares boolean values. However, &
doubles as the non-shortcircuiting logical and, meaning if you have false & true
, the second parameter would still be evaluated. This won't be the case with &&
.
Bitwise, as its name implies, it's an AND operation at the BIT level.
So, if you perform a BITWISE AND on two integers:
int a = 7; // b00000111
int b = 3; // b00000011
int c = a & b; // b00000011 (bitwise and)
On the other hand, in C#, logical AND operates at logical (boolean) level. So you need boolean values as operators, and result is another logical value:
bool a = true;
bool b = false;
bool c = a && b; // c is false
c = a && true; // c is true
But only at the logical level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With