Evaluation of Subexpressions

Precedence and associativity define the order in which operators are applied to their operands. This is only part of the story, though. Another question is when the operands are turned into values that the operators can deal with. One of the reasons this is important is because of the potential side effects that occur during evaluation. Having a deterministic ordering for those is a welcome feature.

Let’s set the scene by tweaking our preceding example just a tiny little bit:

int res = a() + b() * c();

Now a, b, and c are methods (or delegates, as discussed later) that get invoked. Ultimately, those return some value that’s used for the operands of the various operators in this expression. Recall that the multiplication ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.