Operators Precedence in C#


Precedence stands for the priority. Operator precedence determines the output of the expression.

Below are the operators accordings to categories.


Primary Operators

Primary operators has the highest precedence in C#. The associativity of the primary operators is from left to right. The primary operators are

Symbol Operator Description Associativity
a++,a-- Post Increment and Post decrement Increment or Decrement the original value of operand. Left To Right
X.a Accessing member of class. accesing variable a with object X Left To Right
X(a)- Method Invocation Calling method (a) with object X Left To Right
X[a] Element or variable access. Accessing index 'a' with Array 'X' Left To Right
new Object Creation Using new to create object of class. Left To Right
typeof type of datatype To find the Datatype of Object ot Variable Left To Right
checked, unchecked Left To Right

Unary Operators

Unary Operators are the operators who work with only one operand. The operators has the right to left Associatiity. Below are the Unary Operators.

Symbol Operator Description Associativity
+a,-a Unary Plus and unary minus operator Unary Plus and unary minus operator right to left
++a,--a Preincrement , predecrement Preincrement , predecrement right to left
!a Logical Not Reverse the value of the variable right to left
~a Bitwise Not Reverse the value of the bit right to left

Multiplicative Operators

Multiplicative Operators perform multiplication or division. They possess left to right associativity.

Symbol Operator Description Associativity
* Multiplication Multiply two operands left to right
/ Division Divide two operands left to right
% Modulus To calculate reminder of division left to right

Additive Operators

Additive operators perform addition and subtraction. They posses left to right associativity.

Symbol Operator Description Associativity
+ Addition Addition of two numbers Left To Right
- Subtraction Subtraction of two operands Left To Right

Shift Operators

Shift Operators are used to shift the bits either right or left. Shift operators used with bitwise operators.

Symbol Operator Description Associativity
<< Left Shift Shift one bit to the left Left To Right
> Right Shift Shift one bit to right Left To Right

Relational and Type Testing Operators

Relational and Type Testing Operators are used to compare two operands/variables and testing the operands/variables for diffrerent conditions i.e equality, greater than, less than etc.

Symbol Operator Description Associativity
< Less than To test if one operator/variable is less than other Left To Right
<= Less than or Equal To To test if one operator/variable is less than or equal to other Left To Right
> Greater Than To test if one operator/variable is greater than the other Left To Right
>= Greater Thanor Equal to To check whether one perator/variable is Greater Than or Equal to other Left To Right

Equality Operators

To check whether two operands/Variables are equal or not , Equality operators are used. Equality operators have Left To Right Associativity.

Symbol Operator Description Associativity
== Is equal To To Check whether one operand/Variable is equal to other Left To Right
!= Is not equal To To Check whether one operand/Variable is not equal to other Left To Right

Logical Operators

Logical operators used to compare two operand and the result/output of expression using logical operators is boolean format. They possess Left to Right Associativity. For example IF(a&&b==0) then...

Symbol Operator Description Associativity
&& Logical AND Returns True when both the operands returns true Left to Right
|| Logical OR Returns True when one of the operands returns true Left to Right
^ Logical XOR XOR operation between two operands Left to Right

Conditional Operators

Conditional Operators executes expression and select the value between two operands/variables based on output of expression.

Symbol Operator Description Associativity
?:(x?y:z) Conditional Executes operand y if x is true otherwise evalutes z Right To left
Operators Precedence in C# Operators Precedence in C# Reviewed by LanguageExpert on December 20, 2017 Rating: 5

No comments