---
title: "Precedence of Operators in C#"
url: https://weworkworldwide.com/tutorials/precedence-of-operators-in-c-3/
description: "In this section we're assuming you're familiar with C# arithmetic operators. Let's start with a simple expression: `int res = 10 – 2 * 4 /2`; What is the v"
date: 2026-08-13T13:00:03+00:00
source: https://weworkworldwide.com/llms.txt
---

# Precedence of Operators in C#

In this section we’re assuming you’re familiar with *C# arithmetic operators*.

Let’s start with a simple expression:

``` line-numbers
`int res = 10 – 2 * 4 /2`;
```

What is the value that will be set for the `res` variable?

The final value is 6. But how we’ve got this value?

This is where precedence comes in.

Based on precedence rules, arithmetic operators have different priority.

For example the priority of the multiplication `*` operator is higher compared to addition `+` operator and so if we had an expression like `10+5*2` the result will be 20. This means in the expression before, first the two values 5 and 2 are multiplied together and the result is added to the value 10.

In the list below you can see operators in order of decreasing precedence:

| Operators | Associativity |
|-----------|---------------|
| ()        | Left to Right |
| * /      | Left to Right |
| + –      | Left to Right |
| =         | Right to Left |

As the table above shows, parentheses have the highest priority and after that we have `multiplication& division` operators and next is `addition& subtraction` operators and at the end we have `assignment` operator with the lowest precedence.

For example if we had an expression like this:

``` line-numbers
int iVar = (10 + 20) * 10;
In the expression above we have 4 operators which are: `() * + =`
```

Now according to the table above:

-   The parentheses have the highest priority and so it should be  
    resolved first. So the result of the expression in the parentheses will  
    be 30. Note that inside this parenthesis we have an addition operation!  
    But it doesn’t matter what is in the parentheses, they should be  
    resolved first.

-   After that we have the multiplication `*` and the assignment `=`  
    operators. Here the priority of the multiplication is higher and so it  
    should be resolved first.

-   The result of the 30 * 10 is 300 and now there’s only one  
    operation is left and that is assignment operation.

-   So the end the value 300 will be assigned to the `iVar`  
    variable.

``` line-numbers
Associativity:
```

Associativity declares the order of operand execution.

For example the associativity in arithmetic operators is from Left to Right. This means if we have an expression like `4/2*4`, the left operand executes first and then the right operand. So the result of the mentioned expression is:

``` line-numbers
2*4 = 8.
```

Here the priority of both division and multiplication is the same and so according to associativity rules: this expression will be resolved from left to right. Here first the result of the division will be declared and this result will be used as the left operand of the multiplication operation.

Another Example:

``` line-numbers
using System;
```

namespace quickExample

``` line-numbers
{
public class Program
{
public static void Main(string[] args)
{
int a = 10;
int b = 20;
int c = 30;
int d = 40;
int result = (a + b) * d; // (10+20) * 40
Console.WriteLine("The result is: " + result);
result = ((a + b) / 2) * c; // ((10+20)/2) * 30
Console.WriteLine("The result is: " + result);
result = c + d / 10 * d; // 30+((40/10) * 40)
Console.WriteLine("The result is: " + result);
}
}
}
```

Output:

The result is: 1200

The result is: 450

The result is: 190
