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 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.