(You are currently looking at the first edition version of this page. This page is also available for the second and third editions.)

Errata for Chapter 9: Lambda expressions and expression trees

P230: Incorrect use of "covariance"

On page 230 in the introduction to lambda expressions, I incorrectly talk about "parameter covariance". It should be "return type covariance" or "parameter contravariance" - both of which were added with C# 2.

P233, first text line: Extraneous comma

On page 233, in the first line of normal text, there's an extra comma in the quoted output. So where it says:

Listing 9.1 prints "5," just as we'd expect it to.

It should instead read:

Listing 9.1 prints "5" just as we'd expect it to.

The same issue comes up elsewhere in the text - we should probably use an automated "find" to check for all potential candidates.

P236: Briefer code in listing 9.4

The code in listing 9.4 can be abbreviated slightly. The lambda expression used to print the films list doesn't need braces. The code which appears like this:

Action<Film> print = film => { Console.WriteLine(film); };

can be changed to this:

Action<Film> print = film => Console.WriteLine(film);

This change has been made to the downloadable code. See also this note for even more significant abbreviations.

P238: Briefer code in listing 9.5

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.

P238: Swapped words

In the first paragraph of text on page 238, I state:

We don't log the details of the source event, beyond whatever its ToString override returns, because there's an overwhelming amount of information associated with controls.

The phrase "source event" is confusing. The sentence should read:

We don't log the details of the event source, beyond whatever its ToString override returns, because there's an overwhelming amount of information associated with controls.

i.e. "source event" becomes "event source" - basically the first parameter for the event handler.