C # main differences between the condition and & amp; and the condition or |,

Source: Internet
Author: User

C # main differences between conditions and & and conditions or | in languages,
I will not describe it in detail, but I will give you an analysis based on the case. The details are as follows:

The condition "or" Operator (|) executes the logical "or" Operation of the bool operand, but calculates the second operand only when necessary.

And operator (&) executes the logical and operation of its bool operations, but calculates the second operand only when necessary.

We also need to know that | and & are left-bound logical operators, so let's look at the example below.

Class Program {static void Main (string [] args) {int a = 9; int B = 10; int c = 11; int d = 12; if (d> B | c> B & a> B) {Console. writeLine ("true");} Console. readKey ();}}

Therefore, when the value of d> B is determined to be true, the subsequent part of c> B & a> B will not be computed and will enter the Condition Statement.

We hope to help you to get home.

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.