C # Operator Precedence

Source: Internet
Author: User

One, C # operator Precedence

The C # operator is also known as C # operators.

When an expression contains more than one operator, the order of operations for the operator occurs. In C #, the precedence of operators is used to solve the order of operations. The precedence of an operator controls the order in which a single operator evaluates.

Each operator has its own priority, which determines its order of operations in an expression. In the same expression, a high-priority operator is executed before the lower-priority operator, and the same precedence is performed from left-to-right or right-to-left in the same order.

The following is a list of precedence for C # operators, which are sorted by their precedence from highest to lowest. Operators of the same classification have the same precedence.

Second, prompt

? When an operand appears between two operators with the same precedence, the operators are executed from left to right in the order in which they appear.

In addition to the assignment operators, all binary operators are executed in left-to-right order. For example: X+Y+Z is evaluated according to the (X+y) +z.

The assignment operator and the condition operator (?:) are executed in right-to-left order. For example: X=Y=Z is evaluated according to X= (Y=Z).

? If the effective order of the operators is not correctly determined, you can change the order of operations by using parentheses, that is, expressions in parentheses are evaluated first, and expressions outside the parentheses are computed. This effectively determines the order of operations of the operators.

C # Operator Precedence

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.