June 2003
Intermediate to advanced
624 pages
12h 41m
English
Say you wanted to add 10 to 15 and multiply the result by 4; you might use this expression:
10 + 15 * 4
And you might expect the result to be 100. Unfortunately, C# will give you a value of 70. What happened? Instead of adding 10 to 15 and multiplying the result by 4, C# performed the multiplication first, multiplying 15 and 4 and adding the result (60) to 10 to get 70. That's because multiplication has higher precedence than addition, so the multiplication operation in this example was performed first. You can see the C# operator precedence in Table 1.8, from highest to lowest.
| CATEGORY | OPERATORS |
|---|---|
| Primary | x.y f(x) a[x] x++ x-- new typeof checked unchecked |
| Unary | + - ! ~ ... |