Site icon JD Bots

C# Operators with Order of Execution | Operator Associativity

computer program language text

Photo by Jorge Jesus on Pexels.com

When operators have the same precedence, the associativity of the operators determines the order in which the operations are performed.

Below are the two associativity of operators in c#:

  1. Left-associative: The order of execution is from left to right.
  2. Right-associative: The order of execution is from right to left.

Below is the table that shows the Associativity of Operators in C#.

CategoryOperatorsAssociativity
Postfix Increment and Decrement++, —Left to Right
Prefix Increment, Decrement, and Unary++, –, +, -, !, ~Right to Left
Multiplicative*, /, %Left to Right
Additive+, –Left to Right
Shift<<, >>Left to Right
Relational<, <=, >, >=Left to Right
Equality==, !=Left to Right
Bitwise AND&Left to Right
Bitwise XOR^Left to Right
Bitwise OR|Left to Right
Logical AND&&Left to Right
Logical OR||Left to Right
Ternary? :Right to Left
Assignment=, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=Right to Left

Exit mobile version