C # Conditional expression max= (a>b)? a:b; meaning

Source: Internet
Author: User

Tag: operation cannot arithmetic condition style description size Pre Union

A?b:c

This is a conditional expression, which means that if a is true, the expression value is B, and if A is false, the expression value is C
The conditional expression is specified as follows
Conditional statements:

if (a>b) max=A; else max=b;


An available conditional expression is written as

max= (a>b) a:b;


The semantics for executing the statement are: If A>b is true, assign a to max, otherwise assign B to max.
When you use conditional expressions, you should also be aware of the following points:
1) The operator precedence of the conditional operator is lower than the relational operator and the arithmetic operator, but above the assignment.
So

max= (a>b)? a:b


You can remove parentheses and write as

Max=a>b?a:b


2) The conditional operator? And: is a pair of operators and cannot be used separately.
3) The binding direction of the conditional operator is from right to left.
For example:

A>b?a:c>d?c:d


Should be understood as

A>b?a: (C>D?C:D)


This is the case where conditional expressions are nested, where expression 3 is another conditional expression.

C # Conditional expression max= (a>b)? a:b; meaning

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.