How C# Determines Precedence
Let's look specifically at how C# assigns precedence to operators. Table 10-1 illustrates C# operator precedence from highest precedence to lowest precedence. After this section, I'll go into more detail on the different categories of operators that are supported in C#.
Table 10-1 C# Operator Precedence
|
Category of Operator
|
Operators
|
|
Primary
|
(x), x.y, f(x), a[x], x++, x--, new, typeof, sizeof, checked, unchecked
|
|
Unary
|
+, -, !, ~, ++x, --x, (T)x
|
|
Multiplicative
|
*, /, %
|
|
Additive
|
+, -
|
|
Shift
|
<<, >>
|
|
Relational
|
<, >, <=, >=, is
|
|
Equality
|
==
|
|
Logical AND
|
&
|
|
Logical XOR
|
^
|
|
Logical OR
|
|
|
|
Conditional AND
|
&&
|
|
Conditional OR
|
||
|
|
Conditional
|
?:
|
|
Assignment
|
=, *=, /=, %=, +=, -=, <<=, >>=, &=, ^=, |=
|