> ## Content Index
> Fetch the complete content index at: https://davidzych.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# C# Operator Precedence
- URL: https://davidzych.com/c-operator-precedence/
- Published: 2013-06-21T03:48:41.000Z
- Updated: 2026-11-14T12:19:38.000Z
- Author: David Zych
- Tags: decrement, increment, operator, precedence, #Import 2026-11-20 21:02

In my previous blog post on [the difference between i++ and ++i](https://davidzych.com/2013/06/19/whats-the-difference-between-i-and-i-in-c/), I made a comment that `i++` had a higher precedence than `++i`. In C#, operators are grouped into categories and each category has a precedence. Categories with a higher precedence will execute prior to categories with a lower precedence. In the case of `i++` and `++i`, the Postfix increment operator is in the `Primary` operator category and the Prefix increment operator is in the `Unary` category.

In total, C# has [15 operator categories](http://msdn.microsoft.com/en-us/library/6a71f45d.aspx?ref=davidzych.com) (listed in descending order of precedence):

> - [Primary](http://msdn.microsoft.com/en-us/library/aa691342%28v=vs.71%29.aspx?ref=davidzych.com)
> - [Unary](http://msdn.microsoft.com/en-us/library/aa691364%28v=vs.71%29.aspx?ref=davidzych.com)
> - [Multiplicative](http://msdn.microsoft.com/en-us/library/aa691371%28v=vs.71%29.aspx?ref=davidzych.com)
> - [Additive](http://msdn.microsoft.com/en-us/library/aa691371%28v=vs.71%29.aspx?ref=davidzych.com)
> - [Shift](http://msdn.microsoft.com/en-us/library/aa691377%28v=vs.71%29.aspx?ref=davidzych.com)
> - [Relational and type testing](http://msdn.microsoft.com/en-us/library/aa664713%28v=vs.71%29.aspx?ref=davidzych.com)
> - [Equality](http://msdn.microsoft.com/en-us/library/aa664713%28v=vs.71%29.aspx?ref=davidzych.com)
> - [Logical AND](http://msdn.microsoft.com/en-us/library/aa691306%28v=vs.71%29.aspx?ref=davidzych.com)
> - [Logical XOR](http://msdn.microsoft.com/en-us/library/aa691306%28v=vs.71%29.aspx?ref=davidzych.com)
> - [Logical OR](http://msdn.microsoft.com/en-us/library/aa691306%28v=vs.71%29.aspx?ref=davidzych.com)
> - [Conditional AND](http://msdn.microsoft.com/en-us/library/aa691310%28v=vs.71%29.aspx?ref=davidzych.com)
> - [Conditional OR](http://msdn.microsoft.com/en-us/library/aa691310%28v=vs.71%29.aspx?ref=davidzych.com)
> - [Null-coalescing](http://msdn.microsoft.com/en-us/library/aa691313%28v=vs.71%29.aspx?ref=davidzych.com)
> - [Conditional](http://msdn.microsoft.com/en-us/library/aa691313%28v=vs.71%29.aspx?ref=davidzych.com)
> - [Assignment and lambda expression](http://msdn.microsoft.com/en-us/library/aa691314%28v=vs.71%29.aspx?ref=davidzych.com)

When there are two operators with the same precedence, the associativity of the operators determines the order or operations. Except for assignment operators, all binary operators are performed left to right. For example, the operation `i + j + k` is evaluated as `(i + j) + k`. The expression `x OR y OR z` is evaluated as `(x OR y) OR z`.

For the assignment operators and the conditional operator the operations are performed right to left. The statement `x = y + z` is evaluated as `x = (y + z)`, and the statement `x = y = z` is evaluated as `x = (y = z)`.

To control precedence and associativity, you can use parentheses. The statement `x = 1 + 2 * 3` will default to `x = 1 + (2 * 3)`, but you can force the addition operator to run first by using parentheses to create `x = (1 + 2) * 3`.