C # difference between & and &

Source: Internet
Author: User
Console. writeline (1 = 1 & 1 = 1); both the first and second judgments are executed. console. writeline (1 = 1 & 1 = 1); if the previous judgment is false, the subsequent judgment is not executed. returns false directly. it is recommended to use & for a reason. for example, TB is a textboxif (TB! = NULL & TB. Text = "") {} If TB! = If the value of null is true, an error occurs when writing this statement because TB is not used! If the value of = NULL is true or false, TB. Text = "" will be executed. If TB = NULL, there will be no TB. Text. If (TB! = NULL & TB. Text = "") {} If TB! = If the value of null is false, the subsequent judgment will not be executed.


Description on msdn:

For integer andBoolThe Type predefines the Binary & operator. For an integer, & the logic of the calculation operand is bitwise "and ". ForBoolOperand, and the logic of the calculated operand "and"; that is, if and only when both operands areTrueThe result isTrue.

&The operator calculates two operators, independent of the value of the first operand.

Related Article

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.