## C# Operator Priority

C# operator priority describes the order in which operations are performed when a computer evaluates an expression. Operations with higher priority are performed first, and then operations with lower priority are performed. For example, we often say that multiplication and division are performed first, and then addition and subtraction operations are performed.

Priority | Operator | Name or meaning | Usage form | Combination direction | Description |
---|---|---|---|---|---|

1 | [] | Array subscript | Array name[integer expression] | Left to right | |

() | Parenthesis | (Expression)/Function name(parameter list) | |||

. | Member selection (object) | Object.Member name | |||

-> | Member selection (pointer) | Object pointer->Member name | |||

2 | - | Minus operator | -Expression | Right to left | Unary operator |

(type) | Forced type conversion | (data type) expression | |||

++ | Increment operator | ++variable name/variable name++ | Unary operator | ||

-- | Decrement operator | --variable name/variable name-- | Unary operator | ||

* | Value operator | *Pointer expression | Unary operator | ||

& | Address of operator | &Lvalue expression | Unary operator | ||

! | Logical NOT Operator | !Expression | Unary Operator | ||

~ | Bitwise NOT Operator | ~Expression | Unary Operator | ||

sizeof | Length Operator | sizeofExpression/sizeof(Type) | |||

3 | / | Division | Expression/Expression | Left to Right | Binary Operators |

* | Multiplication | Expression*Expression | Binary Operators | ||

% | Remainder (Modulo) | IntegerExpression%IntegerExpression | Binary Operators | ||

4 | + | Addition | Expression+Expression | Left to Right | Binary Operators |

- | Subtraction | Expression-Expression | Binary Operator | ||

5 | << | Left Shift | Expression<<Expression | Left to Right | Binary Operator |

>> | Right Shift | Expression>>Expression | Binary Operator | ||

6 | > | Greater Than | Expression>Expression | Left to Right | Binary Operator |

>= | Greater Than or Equal To | Expression>=Expression | Binary Operator | ||

< | Less Than or Equal To | Expression<=Expression | Binary Operator | ||

rowspan="2">7 | == | Equal to | Expression==Expression | Left to Right | Binary Operator |

!= | Not Equal to | Expression!=Expression | Binary Operator | ||

8 | & | Bitwise AND | Integer Expression&Integer Expression | Left to Right | Binary Operator |

9 | ^ | Bitwise XOR | Integer Expression^Integer Expression | Left to Right | Binary Operator |

10 | | | Bitwise OR | Integer Expression|Integer Expression | Left to Right | Binary Operator |

11 | && | Logical AND | Expression&&Expression | Left to Right | Binary Operator |

12 | || | Logical OR | Expression||Expression | Left to Right | Binary Operator |

13 | ?: | Conditional Operator | Expression1?Expression2:Expression3 | Right to Left | Ternary Operator |

14 | = | Assignment Operator | Variable=Expression | Right to Left | |

/= | Division of post-assigned value | variable/=expression | |||

*= | Multiplication of post-assigned value | variable*=expression | |||

%= | Modulo post-assigned value | variable%=expression | |||

+= | Addition of post-assigned value | variable+=expression | |||

-= | Subtract postfix value | variable-=expression | |||

<<= | Left shift postfix value | variable<<=expression | |||

>>= | Right shift postfix value | variable>>=expression | |||

&= | Bitwise AND postfix value | variable&=expression | |||

^= | Bitwise OR postfix value | Variable^=expression | |||

|= | Bitwise OR postfix value | Variable|=expression | |||

15 | , | Comma operator | Expression, expression,… | Left to right | Operate from left to right |