17 operator precedence | #Mortaltech | #21
Operator Evaluation & Precedence
Evaluation of the operands in an expression starts from left to right. If multiple operators are used in an expression, then the operators with higher priority are evaluated before the operators with lower priority.
The following table lists operators starting with the higher precedence operators to lower precedence operators.
Operators Category
x.y, x?.y, x?[y], f(x), a[i], x++, x--, new, typeof, checked, unchecked, default, nameof, delegate, sizeof, stackalloc, x-y Primary
+x, -x, !x, ~x, ++x, --x, ^x, (T)x, await, &x, *x, true and false Unary
x..y Range
x * y, x / y, x % y Multiplicative
x + y, x � y Additive
x y, x y Shift
x y, x y, x = y, x = y, is, as Relational and type-testing
x == y, x != y Equality
x & y Boolean logical AND
x ^ y Boolean logical XOR
x | y Boolean logical OR
x && y Conditional AND
x || y Conditional OR
x ?? y Null-coalescing operator
c ? t : f Conditional operator
x = y, x += y, x -= y, x *= y, x /= y, x %= y, x &= y, x |= y, x ^= y, x= y, x = y, x ??= y, = Assignment and lambda declaration
The following example demonstrates operator precedence:
Example: Operator Precedence
int a = 5 + 3 * 3;
int b = 5 + 3 * 3 / 2;
int c = (5 + 3) * 3 / 2;
int d = (3 * 3) * (3 / 3 + 5);
You can also find me here:
Instagram: MortalsTech
Facebook: MortalTech
Twitter: Mortalstech
Информация по комментариям в разработке