O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Assignments

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required