The logical operator of the operator

Source: Internet
Author: User

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;&AMP;&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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.