Asp.net trielement operators

Source: Internet
Author: User

Asp tutorial. net ternary operators

The ternary operator is also a conditional operator. It seems special because it has three operands, but it does belong to one of the operators.

The format is

Boolean-exp? Value0: value1

If the boolean-exp expression returns true, value0 is calculated, and the calculation result is the final value produced by the operator. If the boolean-exp expression returns false, value1 is calculated. Similarly, the result is the final value of the operator.

Of course, it can also be replaced by if-else, but the ternary operator and if-else are completely different, and the operator will generate a value.

Public class ternaryifelse {

Static int ternary (int I ){

Return I <10? I * 100: I * 10;

       }

Static int standardifelse (int I ){

If (I <10)

Return I * 100;

Else

Return I * 10;

}

Public static void main (string [] args ){

System. out. println (ternary (9 ));

System. out. println (ternary (10 ));

System. out. println standardifelse (9 ));

System. out. println standardifelse (10 ));

}

}

Output

900

100

900

100

In contrast, the ternary operators are much more compact, and if-else is easier to understand.

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.