C# in Depth

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

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

All Errata

P22/23, listing 1.21: Incorrect formatting

The formatting in listing 1.21 is fine until the last line of page 22 - but that closing brace should be outdented, and then on page 23 the productCheckButton.Enabled = true; line should be indented.

The code will already execute perfectly happily - it's just not pleasant to look at.

P23, section 1.6: Incorrect listing reference

Directly after listing 1.21, I state that "The full method is a little longer than the one shown in listing 1.22," where of course I meant listing 1.21 instead - listing 1.22 doesn't exist.

P24, section 1.7.1: Incorrect URL for Mono

On page 24, there's an incorrect link for the Mono project. (It's not clear to me whether it's always been wrong, or whether the "right" link has changed.) I won't duplicate the incorrect link here, but the right link is https://www.mono-project.com.

P33, figure 2.2: Incorrect figure included (again)

This problem has been fixed. Please download the latest version of the ebook if you see this issue in your version.

Just like in the second edition, figure 2.2 in the ebook is the wrong figure.

Figure 13.1 has accidentally been included again as figure 2.2. The real figure 2.2 should look like this:

Figure 2.2 - delegate combination

P53, listing 2.6: Just how old are you, Jon?

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

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

P98, listing 3.14: Duplicated annotation

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

P119, section 4.3.3: Space missing between true and false

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

P180, section 6.4: Truncated text in code

The first line of the page has various truncated elements. It should read:

static IEnumerable<ITask> ComputeTotalStockVal(string user, string pass)

P212, section 8.2.1: Repeated figure

Figure 8.2 is a duplicate of figure 8.4. It should be a tooltip shown when hovering over a var for a Dictionary type (as described three paragraphs below).

P222, listing 8.3: Extra comma in listing

Listing 8.3 currently includes this:

new Person("Alice"),
    Age = 9,
    Home = { Town = "Twyford", Country = "UK" }

The comma after the constructor call needs to be removed, like this:

new Person("Alice")
    Age = 9,
    Home = { Town = "Twyford", Country = "UK" }

P346, section 12.3.1: XText creation

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 which 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:


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

P396, section 13.3.2: Typo describing variance

The callout in section 13.3.2 contains this text:

Any conversion using variance or covariance is a reference conversion

That appears to suggest that covariance is an alternative to variance... it should read:

Any conversion using covariance or contravariance is a reference conversion

P400, section 13.3.4: The button is missing in action!

The second paragraph below listing 13.15 contains this text:

The TInput parameter is only used in an input position, so it makes sense that you can use it contravariantly, using a Converter<object, string> as a Converter<Button, string>. In other words, if you can pass any object reference into the converter, you can certainly hand it a Button reference.

The listing never deals with buttons at all - only strings. The paragraph should read:

The TInput parameter is only used in an input position, so it makes sense that you can use it contravariantly, using a Converter<object, string> as a Converter<string, string>. In other words, if you can pass any object reference into the converter, you can certainly hand it a string reference.

(Alternatively, imagine the relevant changes in listing 13.15 to use buttons instead... there's nothing special about strings here.)

P406, section 13.4.1: Incorrect method call

In the listing on page 406 - the second listing in section 13.4.1 - I mistakenly have a call to Monitor.Release in the finally block. That method doesn't actually exist; in should be a call to Monitor.Exit, just as it was in the previous listing.

P428, section 14.3.3: Incorrect single/multiple dispatch usage

Beginning on page 428, I talk about single/multiple dispatch, but I don't actually show multiple dispatch, as the implementation is only ever chosen based on a single execution-time type.

Real multiple dispatch - which dynamic typing in C# is entirely capable of - would require an example where either the types of both target of the call and at least one argument, or just multiple arguments, were required to dispatch the method.

It wouldn't be true to call this static vs dynamic dispatch, as C# has always had dynamic dispatch - but only on the type of the target of the call. Dynamic typing in C# 4 adds the ability for overload resolution to be performed dynamically based on execution-time argument types as well as the implementation of the chosen signature based on the execution-time target type.

P473, section 15.3.2: Typo around Task<TResult>

The published text has (just after the list at the start of the section):

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

P500, section 15.5.5: Indentation failure

The first line of the code starting at the bottom of page 500 should be indented. (It's not a label, as the other unindented lines are.)

P503, section 15.5.6: Last line of listing should be bold

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

P503, section 15.5.6: Non-bold line

As indicated by the // Bold comment, the last line of the code at the top of page 503 should be in bold.

P505, section 15.6.1: Note to production still present

In 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!

P505, section 15.6.1 : Naming convention failure

The method declarations near the center of the page should all have a suffix of Async to follow the TAP conventions I was aiming to demonstrate.

P511, section 15.6.2: Missing space

On page 511, just after listing 15.13, there's a sentence missing a space:

There are two slight issues with listing15.13:

This should of course be:

There are two slight issues with listing 15.13:

P522, listing 16.3: Incorrect indentation

In listing 16.3, the body of the attribute constructor (Member = member;) should be indented.

P522, under listing 16.4: Incorrect listing reference

Just under listing 16.4, I accidentally refer to listing 16.3... while giving the output of listing 16.4. So this:

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.

P439, table A.15: Rogue s in results

In the "result" column of table A.15, there's a rogue "s" in the results for the fourth operation. It shouldn't be there.

P534, figure A.7: Incorrect results shown in table

The second example in figure A.7 should have upper case values in each group, so: