Under the Hood

The conditional operator is implemented using branching similar to the if statement. The code shown in Figure 5.24 is the result of an optimized Release build because the Debug code is a bit more involved with temporary compiler-generated variables. Yes, that’s right. The C# compiler knows to optimize code to some extent.

Image

FIGURE 5.24 The conditional operator behind the scenes.

Note: A Word on Optimization

People sometimes freak out when IL code doesn’t look as optimized as they expect it to. The general approach taken by managed code compilers it to limit optimizations and leave some of the potential further optimizations to the ...

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.