Hidden features: "|" and "&" Operators of C # (boolean operators without short-circuit features)

Source: Internet
Author: User

In C,
"|" And "&" boolean operators are short-circuited, which is equivalent to the orelse and andalso operators of VB.
The "|" and "&" operators can be used not only for numerical operations, but also for Boolean operations. As a boolean operator, neither of them has the short circuit feature, which is equivalent to the OR and operator of VB.
Note: In fact, other C series languages (C/C ++ and Java) also have the same language features.

Using system; namespace consoleapplication1 {class program {static bool F () {console. writeline ("F ()"); Return true;} static void main (string [] ARGs) {console. writeline ("B1"); bool b1 = true | f (); B1 | = f (); console. writeline ("B2"); bool b2 = true | f (); b2 = b2 | f (); console. writeline ("B3"); bool B3 = false & F (); B3 & = f (); console. writeline ("B4"); bool B4 = false & F (); B4 = B4 & F () ;}}/* B1F () f () b2b3f () F () B4 */
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.