C # Use the conditional operator (? :)

Source: Internet
Author: User

C # Use the conditional operator (? :), MakeProgramMore concise and elegant expression of those simple if-else structures. However, due to the impact of C language, I always use IIF in this case. I always forget that there is no IIF in C # And only the conditional operator (? :). Write this article today and remind yourself.

Conditional operators (? :) Return one of the two values based on the value of the Boolean expression. The format of conditional operators is as follows:
Condition? First_expression: second_expression;

If the condition is true, the first expression is calculated and Its Calculation Result prevails. If the condition is false, the second expression is calculated and Its Calculation Result prevails. Calculate only one of the two expressions.

Address: http://www.cnblogs.com/anjou/archive/2007/02/28/659831.html

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.