C# in Depth

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

(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 8: Cutting fluff with a smart compiler

P212 and P213: Incorrect variable type claim

At the bottom of page 212, I use an example of:

var args = Environment.CommandLine;

and claim that args would be of type string[]. However, it would be of type string because that's the type of Environment.CommandLine. The same mistake is propagated on page 213, where I provide examples of using implicitly typed local variables for control structures, including this one:

foreach (var s in Environment.CommandLine)

I claim that s is of type string - but it would actually be of type char because string implements IEnumerable<char>.

The fix to both of these problems is simple - just replace the troublesome calls to Environment.CommandLine with Environment.GetCommandLineArgs() which really does return a string[]. The rest of the text is then accurate, and indeed it's the original meaning I intended.

P225, figure 8.3: Curious change in picture

In the published version of the book, the code in the foreach loop in figure 8.3 looks like this:

foreach (var person in family)
    totleAge += person.Age;

Note the typo - totle instead of total. The really odd thing is, I don't know how that mistake came about. Every copy of the image that I can find has the correct variable name. In particular, it would have had a red squiggle underneath it in its current form. Very strange. Anyway, here's what it should look like:

Fixed figure 8.3