Associativity

A relatively minor remark to conclude the discussion of the conditional operator is its right-associative behavior:

condition1 ? a : condition2 ? c : d

The preceding means the same as the following:

condition1 ? a : (condition2 ? c : d)

However, nested conditional operators tend to produce unreadable code quickly (partly due to the terse ?: syntax), so I generally recommend avoiding such use.

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.