C# in Depth

Cover of C# in Depth
Order now (3rd edition)

Briefer code in listing 9.5

Chapter 9: Lambda expressions and expression trees: P238

Created: 5/13/2008
Last updated: 5/13/2008
Severity: Language improvement

The code in listing 9.5 can be abbreviated slightly. The three lambda expressions don't need to have braces. The section which currently reads like this:

button.Click += (src, e) => { Log("Click", src, e); };
button.KeyPress += (src, e) => { Log("KeyPress", src, e); };
button.MouseClick += (src, e) => { Log("MouseClick", src, e); };

can be changed to this:

button.Click += (src, e) => Log("Click", src, e);
button.KeyPress += (src, e) => Log("KeyPress", src, e);
button.MouseClick += (src, e) => Log("MouseClick", src, e);

The changes have been made to the downloadable code.