C# in Depth

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

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

Errata for Chapter 3: Parameterized typing with generics

P94, section 3.5.1: IShape, not Shape

In section 3.5.1, page 94, just above the bulleted list, it states:

We can't convert from an IEnumerable<Circle> to an IEnumerable<Shape>.

However, there's no such type as Shape in our situation - we have an interface instead. So the sentence should actually say:

We can't convert from an IEnumerable<Circle> to an IEnumerable<IShape>.

P96, sample declarations: Incorrect declaration for generic AreaComparer

On page 96, I offer a workaround to the lack of variance in the AreaComparer example. I suggest that we can make the class generic:

class AreaComparer<T> : IComparer<IShape> where T : IShape

class AreaComparer : AreaComparer<IShape>

This wouldn't actually help - we need to implement IComparer<T> in order to use it to sort a List<Circle> or something similar. It can be fixed with just a small change though:

class AreaComparer<T> : IComparer<T> where T : IShape

class AreaComparer : AreaComparer<IShape>