10.1. Operators and their precedence in C#

Table 10.1. C# operators in decreasing order of precedence
Higher precedence
Operator categoryOperators
Primaryx.y f(x) a[x] x++ x-- new typeof checked unchecked
Unary+ – ! ~ ++x --x (T)x
Multiplicative* / %
Additive+ -
Shift<< >>
Relational and type testing< > <= >= is as
Equality== !=
Logical AND&
Logical XOR^
Logical OR|
Conditional AND&&
Conditional OR||
Conditional (ternary)?:
Assignment= *= /= %= += -= <<= >>= &= ^= |=

All operators in the same category have the same precedence. To decide which operator in a particular group takes precedence, follow these associative rules:

  • except for the assignment operators, all other binary operators are left associative – for example, a+b-c is the same as (a+b)-c;

  • the assignment ...

Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.