Errata: May 24, 2021

Thank you for purchasing C# in Depth, Fourth Edition . If you find an error, not listed below, please add it to LiveBook Errata thread. We'll update this list as necessary. Thank you!


Chapter 1, Page 9

A closing bracket is missing the second example. The code should be:

throw new KeyNotFoundException(
    string.Format("No calendar system for ID {0} exists", id));

Chapter 2, Page 35

The declaration for the LastOrDefault method is missing the type parameter T. The first line should be

public T LastOrDefault<T>(IEnumerable<T> source)

Chapter 3, Page 87

"That type representing a favorite color and type isn't likely to be useful anywhere else" should be: "That type representing a favorite color and count isn't likely to be useful anywhere else"

Chapter 11, Page 338

The expansion of the != operator applied to tuples is incorrect. The expansion

Console.WriteLine(t1 != t2);

should be

Console.WriteLine(t1.Item1 != t2.Item1 ||
                  t1.Item2 != t2.Item2 ||
                  t1.Item3 != t2.Item3)

The difference is the use of the || operator; in the book I used the && operator.

Chapter 12, Page 368

Between the code and output, change "The output is mostly straightforward, but you may be surprised by the penultimate line:" to "The output is mostly straightforward, but you may be surprised by the last line:" because it's actually the last line of output that's surprising.

Chapter 13, Page 397, listing 13.13

The code in the Main method on page 397 is incorrect. Please replace it with the following:

static void Main()
{
    int x = 10;
    InParameter(x, () => x++);

    int y = 10;
    ValueParameter(y, () => y++);
}

Chapter 15, Page 443

The compiler then uses that information to warn you if try to misuse a value that might be null.

should be

The compiler then uses that information to warn you if you try to misuse a value that might be null.