Operator precedence and expression disambiguation
For guidance on declaring classes, structs, members, and interfaces, see Classes, structs, and interfaces.
Operators (precedence summary)
Lowest → highest (all left-associative unless noted):
- Assignment:
= += -= *= /= %= &= |= - Null-coalescing:
?? - Logical OR:
|| - Logical AND:
&& - Bitwise OR:
| - Bitwise AND:
& - Equality:
== != - Relational:
< > <= >= - Type tests:
is as(binds after relational) - Range:
..(boundaries optionally prefixed with^) - Additive:
+ - - Multiplicative:
* / % - Cast:
(T)expr - Unary (prefix):
+ - ! fixed stackalloc typeof - Postfix trailers: call
(), member., index[], nullable suppression!, propagation?
🧭 Disambiguation:
(<expr>)is a parenthesized expression unless a comma appears (including trailing), in which case it’s a tuple.<starts type arguments only in a type context; elsewhere it’s the less-than operator.- The LHS of assignment must be either an assignable expression (identifier, member access, element access, etc.) or a pattern such as a positional deconstruction.
^index expressions are parsed as an adjacent prefix form (^expr); whitespace between^and the operand is not allowed.- Prefix unary
+/-are also adjacent forms (+3,-2); whitespace between the operator and operand is not allowed.