Operator Precedence
suggest changeAll operators have a particular “precedence” depending on which group the operator falls in (operators of the same group have equal precedence). Meaning some operators will be applied before others. What follows is a list of groups (containing their respective operators) ordered by precedence (highest first):
- Primary Operators
a.b- Member access.a?.b- Null conditional member access.->- Pointer dereferencing combined with member access.f(x)- Function invocation.a- Indexer.a?- Null conditional indexer.x++- Postfix increment.x--- Postfix decrement.new- Type instantiation.default(T)- Returns the default initialized value of typeT.typeof- Returns theTypeobject of the operand.checked- Enables numeric overflow checking.unchecked- Disables numeric overflow checking.delegate- Declares and returns a delegate instance.sizeof- Returns the size in bytes of the type operand.
- Unary Operators
+x- Returnsx.-x- Numeric negation.!x- Logical negation.~x- Bitwise complement/declares destructors.++x- Prefix increment.--x- Prefix decrement.(T)x- Type casting.await- Awaits aTask.&x- Returns the address (pointer) ofx.*x- Pointer dereferencing.
- Multiplicative Operators
x * y- Multiplication.x / y- Division.x % y- Modulus.
- Additive Operators
x + y- Addition.x – y- Subtraction.
- Bitwise Shift Operators
x << y- Shift bits left.x >> y- Shift bits right.
- Relational/Type-testing Operators
x < y- Less than.x > y- Greater than.x <= y- Less than or equal to.x >= y- Greater than or equal to.is- Type compatibility.as- Type conversion.
- Equality Operators
x == y- Equality.x != y- Not equal.
- Logical AND Operator
x & y- Logical/bitwise AND.
- Logical XOR Operator
x ^ y- Logical/bitwise XOR.
- Logical OR Operator
x | y- Logical/bitwise OR.
- Conditional AND Operator
x && y- Short-circuiting logical AND.
- Conditional OR Operator
x || y- Short-circuiting logical OR.
- Null-coalescing Operator
x ?? y- Returnsxif it is not null; otherwise, returnsy.
- Conditional Operator
x ? y : z- Evaluates/returnsyifxis true; otherwise, evaluatesz.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents