using system;using system.collections.generic;using system.linq;using system.text; Namespace _8. Operator's logical operator { class program { static void main (String[] args) { // The logical operator is also called the conditional Boolean operator bool b1 = true, b2 = false; Console.WriteLine ("!{ 0} = {1} ", &NBSP;B1,&NBSP;!B1); console.writeline ("!{ 0} = {1} ", &NBSP;B2,&NBSP;!B2); console.writeline ("{0} & {1} = {2}", &NBSP;B1,&NBSP;B2,&NBSP;B1&NBSP;&&NBSP;B2); console.writeline ("{0} | {1} = {2} ", &NBSP;B1,&NBSP;B2,&NBSP;B1&NBSP;|&NBSP;B2); console.writeline ("{0} ^ {1} = {2}", b1, b2, &NBSP;B1&NBSP;^&NBSP;B2); // & and &&, | and | |, the latter having short-circuit properties, the former has no such property. // difference: Both check the value of the first action and then manipulate it according to the value of that operand , the second operand may not be processed at all. int a = 5, b = 3; bool result; result = true & a++ > 6; console.writeline ("A = {0}, result = {1}", a, result); a = 5; result = false && a++ > 6; console.writeline ("a = {0}, result = {1} ", a, result); result = false | b++ > 5; console.writeline ("a = {0}, result = {1} ", b, result); b = 3; result = true | | b++ > 5; Console.WriteLine ("A = {0}, result = {1}", b, result); // Logical Assignment operator /** * <variable> &= <expression> equivalent to <variable> = <variable> & ( <expression>) * <variable> |= < expression> equivalent to <variable> = <variable> | (<expression>) * <variable> ^= <expression> equivalent to <variable> = <variable> ^ (< expression>) */ // ! The compound assignment operator is not present (logical) because it is misunderstood to write != and is considered not equal to the operator. // does not exist &&= and | | = Compound assignment operator. console.readkey (); } }}/** * ! (non-logical) if the operand is false, the result is true, and if the operand is true, the result is false. * & (logic and) False if two operands are true and the result is true. * | (logical OR) true if two operands are false and the result is false. * ^ (Logical XOR) False if there is only one true in the two operands and the result is true. * * && (logic and) False if two operands are true and the result is true. * | | (logical OR) true if two operands are false and the result is false. * */
This article is from the "MK IT Life" blog, so be sure to keep this source http://vikxiao.blog.51cto.com/9189404/1586115
The logical operator of the operator