C# in Depth, Third Edition
Errata
“C#

Thank you for purchasing C# in Depth, Third Edition. Please post any errors, other than those listed below, in the book's Author Online Forum. We'll compile a comprehensive list and publish it here for everyone's convenience. Thank you!

Last updated January 8, 2015

Page 22, Listing 1.21:

The formatting in listing 1.21 is fine until the last line of page 22. The closing brace should be outdented. The productCheckButton.Enabled = true; line should be indented. The code will execute; it's just not pleasant to look at.

Page 23, Section 1.6:

Directly after Listing 1.21, I state that "The full method is a little longer than the one shown in Listing 1.22;" I meant Listing 1.21.

Page 53, Listing 2.6:

Eagle-eyed readers may have noticed that in Listing 2.6, I claim to be 31 years old, whereas in later listings throughout the book I'm 36 or 37. Sad to say, it's the latter, which was correct as the third edition went to print. I was born in June 1976. These days I can barely remember what it was like to be 31.

In fact, this was a problem in the second edition as well. It seems that chapter 2 is a chapter of eternal youth, basically. All the code works, it's just the data is inconsistent between editions.

This actually raises an interesting point about storing time-sensitive data: always try to store a fixed reference point rather than a dynamic value. If I'd had a DateOfBirth property instead of an Age property, nothing would have needed updating between editions. That's what I'd have done for real code, but Age = 37 is a good deal shorter than DateOfBirth = new DateTime(1976, 6, 19) even leaving aside the thorny issue of how suitable DateTime is for storing a date.

Page 98, Listing 3.14:

The second annotation in Listing 3.14 is "Uses implicit conversions to call comparer" (the same as the third annotation). It should be:
Remembers original comparer

Page 119, section 4.3.3:

The list of overloadable operators includes truefalse. This should be true false (two different operators).

Page 222, Listing 8.8:

Listing 8.3 currently includes the following:
new Person("Alice"),
{
    Age = 9,
    Home = { Town = "Twyford", Country = "UK" }
}
The comma after the constructor call needs to be removed, as follows:
new Person("Alice")
{
    Age = 9,
    Home = { Town = "Twyford", Country = "UK" }
}

Page 346, Section 12.3.1:

When describing XText, the book states:

XText is rarely instantiated directly in user code; instead, when a string is used as the content of an element or document, that's converted into an XText instance.

That's somewhat misleading, as it ignores all the other conversions that implicitly create XText nodes. Basically, any time you create text within an element, it will be a form of XText. For example, consider this code:
new XElement("x", 0)
This creates this XML:
<x>0</x>
The 0 has been specified as an integer literal, but in the object tree there's still an XText object, as you can tell by calling element.Nodes().First().GetType().

Page 406, Section 13.4.1:

I mistakenly have a call to Monitor.Release in the final block. That method doesn't actually exist; it should be a call to Monitor.Exit, as it was in the previous listing.

Page 473, Section 15.3.2:

The text after the list at the start of the section is as follows:

The difference between the two is essentially that Task<TResult> represents an operation that returns a value of type T [...]

The T should be TResult:

The difference between the two is essentially that Task<TResult> represents an operation that returns a value of type TResult [...]

Page 503, Section 15.5.6:

The last line of the listing on page 502 has a comment of // Bold at the end. That was an instruction to make the line bold, rather than a normal C# comment. Unfortunately, it wasn't picked up during layout.

Page 505, Section 15.6.1:

There's a note I left to the Manning production department:
// NOTE TO PRODUCTION: Please consult with Jon on formatting. Do not abbreviate!
Obviously this shouldn't have appeared in the final copy. Sorry about that!

Page 511, Section 15.6.2:

After Listing 15.13, there's a sentence missing a space:
There are two slight issues with Listing15.13:
This should be:
There are two slight issues with Listing 15.13:

Page 522, Listing 16.3:

The body of the attribute constructor (Member = member;) should be indented.

Page 522:

After Listing 16.4, I accidentally refer to Listing 16.3 while giving the output of listing 16.4:
Listing 16.3 just prints Called by: Unknown as if the output weren't present.
Should be:
Listing 16.4 just prints Called by: Unknown as if the output weren't present.