Assignments are generally considered to be statements in the first place, even though we discussed them in the context of expressions before. In 99 percent of cases, assignments will take a statement form:

name = "Bart";age = 25;age += 1;

In Chapter 5, you saw how assignment expressions take on the value that is assigned to the left side. Although this is definitely a nice property, it should be used sparingly. One of the few legitimate uses I can think of is the type switch mentioned in Chapter 6, “A Primer on Types and Objects,” the section, “Intermezzo: The Mythical Type Switch.”

if ((f = item as Fruit) != null){    // Do something with the juicy piece of fruit...}

Because you already know everything ...

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.