CHAPTER 13

image

Operators and Expressions

The C# expression syntax is very similar to the C/C++ expression syntax.

Operator Precedence

When an expression contains multiple operators, the precedence of the operators controls the order in which the elements of the expression are evaluated. The default precedence can be changed by grouping elements with parentheses.

int value1 = 1 + 2 * 3;        // 1 + (2 * 3) = 7int value2 = (1 + 2) * 3;      // (1 + 2) * 3 = 9

In C#, all binary operators are left-associative, which means that operations are performed left to right, except for the assignment and conditional (?:) operators, which are performed right ...

Get A Programmer's Guide to C# 5.0, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.