Original address: http://www.cnblogs.com/chinafine/archive/2009/02/17/1392309.html thank Bo Master to share!
Binary operators (&) pre-defined binary & operators for integer and bool types. For integer,&, the bitwise "and" of the operands are computed. The logical "and" of the operands is computed for the bool operand,&, that is, the result is true if and only if the two operands are true. The condition and operator (&&) performs the logical AND (&) operation of the boolean operand.
The following example best describes the problem:
usingSystem;classTest {Static BOOLfn1 () {Console.WriteLine ("Fn1 called"); return false; } Static BOOLfn2 () {Console.WriteLine ("Fn2 called"); return true; } Public Static voidMain () {Console.WriteLine ("Regular and:"); Console.WriteLine ("result is {0}", Fn1 () &fn2 ()); Console.WriteLine ("Short-circuit and:"); Console.WriteLine ("result is {0}", FN1 () &&fn2 ()); } }
Output:
Regular and:
Fn1 called
Fn2 called
Result is False
Short-circuit and:
Fn1 called
Result is False
BTW
(&) can also be used as a unary operator to return the address of an operand
Ps.
(|) Same as the (| |) operator
Reprint: The difference between & and && in C #