C# 4.0 in a Nutshell

Errata for C# 4.0 in a Nutshell

Submit your own errata for this product.


The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color Key: Serious Technical Mistake Minor Technical Mistake Language or formatting error Typo Question Note Update



Version Location Description Submitted By Date Submitted Date Corrected
Printed
Page 15
top, first paragraph

text refers to the "Test" class in the code on page 15. second line of text in the paragraph: "the Test class could not access it." in the code on page 15, there is no Test class - the class is called "Program"

Note from the Author or Editor:
In the code sample, change "class Program" to "class Test".

joseph wyatt  Oct 21, 2010  Jun 03, 2011
Printed
Page 18
2nd paragraph

The sentence "If we repeat the previous example, but with Point now a class, an operation to X affects Y:" is a bit misleading. It should probably read "If we repeat the previous example, but with Point now a class, an operation to p1 affects p2:"

Jonas Collberg  May 09, 2011  Jun 03, 2011
Printed
Page 27
1st paragraph in "Real Number Rounding Errors"

"float and double 1internally ..." -> "float and double internally ..."

Anonymous  Jan 11, 2011  Jun 03, 2011
Printed
Page 38
first line under table heading "Parameter modifier"

Wrong font for "None" -- it should be roman or blank as it is not a keyword.

Anonymous  Jan 11, 2011  Jun 03, 2011
Printed, PDF
Page 39 in pdf, 38 in print
2nd paragraph

"fields are implicitly assigned to a default value": the "to" should be deleted.

Note from the Author or Editor:
Agree.

richard.albury  May 01, 2011  Jun 03, 2011
Printed
Page 47
Shift operators (near the bottom of the table)

The example for the Shift Left operator uses the Shift Right operator and vice versa.

Note from the Author or Editor:
Replace "x >> 1" with "x << 1" and vice-versa.

Hanna Ruotsalainen  Nov 02, 2010  Jun 03, 2011
Printed
Page 55
Last paragraph

Instead of 'goto case-constant', it should be 'goto case case-constant', as correctly stated a few lines before.

Gorpik  Mar 09, 2010  Jun 03, 2011
Printed
Page 57
Last paragraph and example

The "previous example" mentioned is missing; probably it was edited out.

Note from the Author or Editor:
Sure - delete that sentence ("This example is semantically identical to our previous example").

Gorpik  Mar 09, 2010  Jun 03, 2011
Printed
Page 65
Last paragraph

Even thought the section is "Instance Constructors", maybe you should clarify that "Instance constructors allow the following modifiers", so it is clear that this does not apply to static constructors.

Note from the Author or Editor:
Good call - change "Constructors" to "Instance constructors" in the last paragraph of page 65.

Gorpik  Mar 09, 2010  Jun 03, 2011
Printed
Page 68
Section on Object Initializers Versus Optional Parameters

The section discusses a feature of C# 4.0, but that is not called out anywhere in the box. Also, the last line on page 67 reads, "Object Initializers were introduced in in C# 3.0.", which is correct, but is confusing when the boxed section starting on 68 discusses Object Initializers in more detail but in relation to C# 4.0 Optional Parameters. I recommend appending "(C# 4.0)" to the title in the boxed section.

Note from the Author or Editor:
Append "(C# 4.0)" to the title in the boxed section.

Stan Morris  Mar 21, 2010  Jun 03, 2011
Printed
Page 71
First line of code

Return type for get_CurrentPrice should be decimal, not int.

Note from the Author or Editor:
Change "int" to "decimal" in first line of first code listing on page 71

Gorpik  Mar 09, 2010  Jun 03, 2011
Printed
Page 81
subheading

Replace “new versus virtual” with “new versus override”

Note from the Author or Editor:
Agree. Replace heading "new versus virtual" with "new versus override". Note to editors: This heading needs to be entirely in lower case, because we're referring to case-sensitive language constructs.

HowardW39  Dec 19, 2010  Jun 03, 2011
Printed
Page 88
Object Member Listing

In the list of Object members, it should be: protected virtual void Finalize(); instead of: protected override void Finalize();

Gorpik  Mar 11, 2010  Jun 03, 2011
Printed
Page 99
list of operators in Enum Operators Section

I believe that the second - (minus) operator should be -- (decrement) i.e. (second row of operators) += -= ++ -- sizeof

Note from the Author or Editor:
Yes. It should read "++ --" rather than "++ -".

guest  May 25, 2011  Jun 03, 2011
Printed
Page 106
5th paragraph

"CompareTo returns a positive number if other is greater than this" should be "CompareTo returns a positive number if this is greater than other".

Gorpik  Mar 10, 2010  Jun 03, 2011
Printed
Page 106
"Generic Constraints" section

This section explains that base class constraint and naked type constraint require the type parameter to derive from the type specified in the constraint. In fact, it can also be the type specified. AFAIK, this is the only place in C# where a class is considered to inherit from itself, so I think it should be clarified.

Note from the Author or Editor:
Yes, you're right. It will be somewhat awkward to fix this in a reprint, though (it requires restructuring the sentences to make it clear) so we'll change this in the next edition.

Gorpik  Mar 10, 2010 
Printed
Page 106
2nd paragraph

In the example code, "class GenericClass<T> where..." should read "class GenericClass<T,U> where..."

K. L. Estes  May 22, 2010  Jun 03, 2011
Printed
Page 109
Covariant example at bottom of page

The variable names are backwards. 'B', 'b' and 'S', 's' names represent 'Base' and 'Subclass' types and variables. The example uses 'b' as the name for the reference variable for an interface using the Subclass type. It should read: IFoo<string> s = ...; IFoo<object> b = s;

Stan Morris  Mar 28, 2010  Jun 03, 2011
Printed
Page 116
Beginning of section "Writing Plug-In Methods with Delegates"

Replace "delegatevariable" with "delegate variable".

Gorpik  Mar 11, 2010  Jun 03, 2011
Printed
Page 118
last paragraph

"When a delegate object is assigned to an instance method" -- remove the word "to", or rewrite as "When an instance method is assigned to a delegate object". This section may be clearer if prefaced with: "The previous examples all used static target methods." (italicize "static") This section uses the terminology "delegate object" but previous sections used "delegate instance" or "delegate variable". Perhaps "delegate variable" is better to avoid confusion with the two meanings of the word "instance" here. Or stick with "object".

Note from the Author or Editor:
Sure - remove the word 'to'. "When a delegate object is assigned an instance method..."

Dan  Sep 05, 2010  Jun 03, 2011
Printed
Page 124
in sidebar

Complete the correction to the example code. Change public event EventHandler Progress; to public event EventHandler PriceChanged;

Note from the Author or Editor:
Note that this change applies only to the code in the sidebar. The third line of the code listing should be: public event EventHandler PriceChanged;

Anonymous  Jan 11, 2011  Jun 03, 2011
Printed
Page 124
Box

The event does not fit to the example. False: public event ProgressReporter Progress; Right: public event EventHandler PriceChanged;

Note from the Author or Editor:
In the code listing in the sidebar "How Do Events Work on the Inside?", the word "ProgressReporter" should be replaced with "EventHandler".

Anonymous  Feb 28, 2010  Mar 01, 2010
Printed
Page 152
Last code snippet

The set function in the Color property is technically correct, but I think it would not behave as expected. Instead of: set { color = Color == parent.Color ? (Color)null : value; } I think it should be: set { color = value == parent.Color ? (Color)null : value; }

Gorpik  Mar 15, 2010  Jun 03, 2011
Printed
Page 152
First section, 3rd paragraph.

In the 'Null Coalescing operator' section, it is stated that the difference between using ?? and calling GetValueOrDefault with an explicit default value is that "the expression passed to GetValueOrDefault is never evaluated if the variable is not null". This is the other way around: the expression to the right of the ?? operator is not evaluated if the left part is not null, but the expression passed to GetValueOrDefault is always evaluated. --> should become 'the expression passed to the right of the ?? operator is never evaluated if the variable is not null'.

Note from the Author or Editor:
Change "expression passed to GetValueOrDefault" to "expression for the default value".

AlvinMinring  Mar 31, 2011  Jun 03, 2011
PDF
Page 153
2nd statement

Console.WriteLine (s); // -1 should be: Console.WriteLine (i); // -1

Anonymous  May 17, 2010  Jun 03, 2011
Printed
Page 161
1st paragraph

The property names must also be the same for both instances to have the same underlying type.

Note from the Author or Editor:
Change the first sentence on page 161 to: Two anonymous type instances declared within the same assembly will have the same underlying type if their elements are named and typed identically:

Gorpik  Mar 15, 2010  Jun 03, 2011
Printed
Page 165
Footnote

The conversion from dynamic 'expressions' to other types is no longer an assignment conversion but an implicit conversion. See Chris Burrows' blog post on 1 April 2010 (http://blogs.msdn.com/b/cburrows/) for details of the change.

Note from the Author or Editor:
Sure: remove the footnote from that page

Alan Fox  Jun 28, 2010  Jun 03, 2011
Printed
Page 165
First code example in section "Dynamic Conversions"

In the code example: int i = 1; dynamic d = i; int j = d; According to the next paragraph that provides description of the example, declaration of "j" variable should be of "long" type.

Note from the Author or Editor:
Change "int j" to "long j".

Michal Jakubec  Oct 31, 2010  Jun 03, 2011
Printed
Page 166
4th code snippet

The following example is used to illustrate the fact that casting a dynamic expression to a static type yield a static expression: dynamic x = 2; var y = (int)2; However, '2' is not a dynamic expression, and the cast adds nothing. The second line of the example probably should have been: var y = (int)x;

Note from the Author or Editor:
Agree.

AlvinMinring  Apr 04, 2011  Jun 03, 2011
Safari Books Online
174
First code block

The last line of code (declaring j) should have type long, otherwise the following comment "The preceding example worked because an int is implicitly convertible to a long." makes no sense.

Note from the Author or Editor:
Page 165, section "Dyanmic Conversions", first code listing. In last line of code listing, int should be changed to long so that it reads: long j = d;

Richard Cox  Apr 11, 2010  Jun 03, 2011
Printed
Page 175
Last paragraph in section "Conditional Attributes"

"The compiler will not incorporate..." should be "The compiler will only incorporate...".

Gorpik  Mar 15, 2010  Jun 03, 2011
Printed
Page 175
last line in Table 4-1

Change "#end 'region'" to "#endregion"

Note from the Author or Editor:
This is on page 175.

Anonymous  Jan 11, 2011 
Printed
Page 175
paragraph preceding "Pragma Warning"

Wrong font for "DEBUG".

Note from the Author or Editor:
The word 'DEBUG' should be in fixed-width font.

Anonymous  Jan 11, 2011  Jun 03, 2011
Printed
Page 209
1st paragraph in section "Text Encodings and Unicode"

The ASCII set is the first 128 (0-127) characters of the Unicode set, not the first 127.

Note from the Author or Editor:
This is on page 203 in the printed edition.

Gorpik  Mar 15, 2010  Jun 03, 2011
Printed
Page 225
2nd line

Shouldn't there be a "minus" before "one"? And, on a meta-level, shouldn't "minus" be "negative"?

Note from the Author or Editor:
The code listing should include the word 'minus' and read: -$123.45 in words is minus one two three point four five

Anonymous  Jan 11, 2011  Jun 03, 2011
Printed
Page 227
Table 6-3

Several results in the table are wrong. Exponent notation: results should be 1E3 (not 1E0), 1E+3 (OK), 1.23E03 (not 1.25E03), 1.23e03 (not 1.25e03). Section separator: results should be 15 (OK), (5) (instead of -5), zero (OK). Literal: result should be $35 . 20c (instead of $35 . 00c).

Note from the Author or Editor:
Correct. 7th row, 4th column should start with 1E3 rather than 1E0 and the last two lines should start with 1.23..... rather than 1.25..... Third-to-last row, 4th column should be (5) (i.e., 5 in brackets) rather than -5 and the last row, 4th column should be $35 . 20 rather than $35 . 00.

Gorpik  Mar 17, 2010  Jun 03, 2011
Printed
Page 238
3rd paragraph in section "BigInteger"

Method name is Pow, not PoW (as correctly stated in the example below).

Note from the Author or Editor:
Change "such as PoW" to "such as Pow"

Gorpik  Mar 17, 2010  Jun 03, 2011
Printed
Page 266
3rd paragraph

In the IEnumerable<T> and IDisposable section on page 266, I think all instances of IEnumerable<T> are supposed to be replaced with IEnumerator<T>. At least, that's what makes the most sense in context of the previous section (IEnumerable<T> doesn't inherit IDisposable, IEnumerator<T> does).

Note from the Author or Editor:
Change "IEnumerable<T> implements IDisposable..." to "IEnumerator<T> implements IDisposable".

BrettS  Mar 24, 2010  Jun 03, 2011
Safari Books Online
267
4th para after list of rules

Default ValueType.GetHashCode() uses only the first field of the struct for the hash value. Demonstrated: using System; struct Test { public int Num; public string Str; } static class Program { static void Main() { Test t = new Test { Num = 10, Str = "" }; Console.WriteLine( t.GetHashCode() ); t.Str = "Test"; Console.WriteLine( t.GetHashCode() ); } } Reverse order of the fields, and different hash values result.

Note from the Author or Editor:
Replace: "The default for structs simply performs a bitwise exclusive OR on each of the fields, which typically generates more duplicate codes than if your wrote the algorithm yourself" With: "The default implementation for structs is at the discretion of the runtime and may be based on every field in the struct."

Steve Love  Feb 10, 2011 
Printed
Page 283
near the middle

Change “from the existing collecting” to “from the existing collection.”

HowardW39  Dec 19, 2010  Jun 03, 2011
Printed
Page 291
4th code listing

Comment should be fhi instead of fhk.

Gorpik  Mar 25, 2010  Jun 03, 2011
Printed
Page 291
Text before 5th listing

"We remove all the vowels from our set of characters in the following code:" It should be "We remove all the non-vowels [...]"

Gorpik  Mar 25, 2010  Jun 03, 2011
Printed
Page 291
Text before 5th listing

Should be IntersectWith instead of IntersectsWith.

Note from the Author or Editor:
Agree.

AlvinMinring  Apr 06, 2011  Jun 03, 2011
Printed
Page 296
2nd paragraph from the end

"None of the three collections allows duplicate keys". In this section (Sorted Dictionaries), only two collections are mentioned. A third one (the non-generic SortedList) is mentioned in a footnote, so I suspect an editing problem here.

Note from the Author or Editor:
Sure. Let's change that sentence to "Neither of these collections allows duplicate keys..."

Gorpik  Mar 26, 2010  Jun 03, 2011
Printed
Page 311
1st paragraph in section Getting Started

Tom, Dick and Harry are not variables (like names), but string literals. So they should be "Tom", "Dick" and "Harry".

Gorpik  Mar 29, 2010  Jun 03, 2011
Printed
Page 320
Last paragraph before tip

Two typos in this paragraph. In the first sentence, it should be "end" instead of "ends" (matches with "query expressions"). In the second sentence, it should be "a range variable" instead of "an range variable".

Gorpik  Mar 29, 2010  Jun 03, 2011
Printed
Page 339
3rd paragraph

The vowel-removed version is called vowelless in the code example, not v.

Note from the Author or Editor:
Correct. That paragraph should end as follows: "... or its vowel-removed version (vowelless)."

Gorpik  Apr 05, 2010  Jun 03, 2011
Printed
Page 364
Tip

In the code snippet, replace ] with }

Note from the Author or Editor:
Sure. That line should read: { return true; } // Code blocks are not permitted

Gorpik  Apr 05, 2010  Jun 03, 2011
Printed
Page 373
Section Overview, last paragraph

"a range" instead of "an range".

Gorpik  Apr 05, 2010  Jun 03, 2011
Printed
Page 375
Distinct paragraph

I think Distinct actually has an overload that accepts an equality comparer that can be used instead of the default one.

Note from the Author or Editor:
Change 'Only the default equality comparer can be used for equality comparison' to 'You can optionally pass in a custom equality comparer.'

Vincent Croquette  Jan 03, 2011  Jun 03, 2011
Printed
Page 391
2nd paragraph after the tip

There is a reference to a variable (outerSeq) that has not been mentioned before. It should probably be query or custPurcharses.

Note from the Author or Editor:
Half way down page 391, change the word 'outerSeq' to 'purchaseSequence': "...because purchaseSequence has no reference to..."

Gorpik  Apr 05, 2010  Jun 03, 2011
Printed
Page 398
1st code example

In the last line inside the foreach block, it should be " -- " instead of " - "

Gorpik  Apr 05, 2010  Jun 03, 2011
Printed
Page 399
2nd code example

The explanation says that we want to filter out groups that have fewer than five files in them, so the filter should be: where grouping.Count() >= 5 instead of: where grouping.Count() < 5

Gorpik  Apr 05, 2010  Jun 03, 2011
Printed, PDF
Page 400
"Concat and Union" section, 1st paragraph, 1st sentence

"Contact returns all the elements of the first sequence..." This should be... "Concat returns all the elements of the first sequence..."

Leonard Thieu  Aug 19, 2010  Jun 03, 2011
Printed
Page 410
5th pseudo-code fragment

Using ! to highlight the unexpected results (365!, 35!) makes them look like factorials.

Note from the Author or Editor:
Sure. Remove the exclamation marks.

Gorpik  Apr 06, 2010  Jun 03, 2011
PDF
Page 437
lower part of p.437

original sentence: XName also overloads the + operation, allowing you to combine a namespace and name without using braces: shoule be: XNamespace also overloads the + operation, allowing you to combine a namespace and name into XName without using braces: reference: Type: System.Xml.Linq.XNamespace public static XName operator +(XNamespace ns, string localName)

Note from the Author or Editor:
Should be: XNamespace also overloads the + operator, allowing you to combine a namespace and name into an XName without using braces:

aligado  Aug 26, 2010  Jun 03, 2011
Printed, PDF
Page 448
Last paragraph, Last sentence

"The default value for CloseInput and CloseOutput is true." This should be... "The default value for CloseInput and CloseOutput is false."

Leonard Thieu  Aug 19, 2010  Jun 03, 2011
Printed
Page 467
last code segment on page

(last code segment at the bottom of 467, 4th ed): XDocument doc = XDocument.Load( ... Xelement e = e.XPathSelectElement( ... Last code line should be Xelement e = doc.XPathSelectElement( ...

Note from the Author or Editor:
Replace "XElement e = e" with "XElement e = doc".

Anonymous  Oct 01, 2010  Jun 03, 2011
Printed
Page 686
3 lines from the bottom

There is an extra 'd' at the end of the line. Delegate staticD = Delegate.CreateDelegate (typeof (IntFunc), typeof (Program), "Square");d

Note from the Author or Editor:
Change ";d" to ";".

Larry Hutcherson  Mar 03, 2011  Jun 03, 2011
Printed
Page 719
Paragraph 2, Line 1

The compiled code in an ssembly contains almost all of the content ... should be: The compiled code in an assembly contains almost all of the content ...

Note from the Author or Editor:
This is on page 681 in the printed edition.

Anonymous  Mar 23, 2010  Jun 03, 2011
Printed
Page 720
3rd paragraph

By convention, their names are csn3ed By convention, their names are prepended?

Note from the Author or Editor:
Change "csn3ed" to "prefixed".

Vincent Croquette  Mar 11, 2011  Jun 03, 2011
Printed
Page 759
The sentence before the first bullet point in the "APTCA and [SecurityTransparent]" section

This sentence states : "To allow such calls, you must do one of two things to X: By "X", I assume the fully trusted assembly is meant.

Note from the Author or Editor:
Confirmed: the line should read: To allow such calls, you must do one of two things to the fully trusted assembly.

JimboT  Feb 21, 2011  Jun 03, 2011
Printed
Page 780
1st paragraph

This frustrates hackers in two ways: hashes take longer to compute, and they ??made?? not have access to the salt bytes. (may?)

Note from the Author or Editor:
Confirmed: change 'made' to 'may'

Vincent Croquette  Feb 08, 2011  Jun 03, 2011
PDF
Page 794
2nd paragraph

"If _a_ such an assembly runs in a sandbox, any Demands that it makes are still subject to the sandbox’s permission set." Unneeded article 'a'.

Note from the Author or Editor:
This is on page 754 in the printed edition.

Ben Monroe  May 24, 2010  Jun 03, 2011
Printed
Page 840
Last sentence of 2nd paragraph in the section "Alternatives to WaitAll and SignalAndWait"

The last sentence states : "..., and see how Task.ContinueWithAny provides an alternative to WaitAny). The Task class does not have a method named "ContinueWithAny". It does have various overloads of the method "ContinueWith", and has overloads of the methods "Wait", "WaitAll", and "WaitAny".

Note from the Author or Editor:
This should read: "..and see how TaskFactory’s ContinueWhenAny provides an alternative to WaitAny.)

JimboT  Feb 22, 2011  Jun 03, 2011
Printed, PDF, Safari Books Online, Other Digital Version
Page 860
Second code listing plus last code listing on page

Second code listing on page, 4th line: property accessor should needs type declaration. Instead of: public Expensive it should read: public Expensive Expensive (the word Expensive should be repeated). The same correction should be made to last code listing on page, 4th line in code listing. Also, on page 861, the very first line on page (code listing) should end in: ... = new Expensive(); rather than: ... = new Foo();

Joseph Albahari
Joseph Albahari
O'Reilly Author 
Aug 12, 2010  Jun 03, 2011
Printed
Page 871
Second and third sentences of first paragraph after code

The second and third sentences state : "This means that the callback method or Tick event may fire on a different thread each time it is called. Furthermore, a Tick always fires (approximately) on time - regardless of whether the previous Tick has finished executing." The class Timer in namespace System.Timers does not have an event named "Tick", but rather an event named "Elapsed". The second and third sentences should therefore state : "This means that the callback method or Elapsed event may fire on a different thread each time it is called. Furthermore, an Elapsed always fires (approximately) on time - regardless of whether the previous Elapsed has finished executing."

JimboT  Feb 22, 2011  Jun 03, 2011
Printed
Page 885
2nd sentence of last paragraph on page

The 2nd sentence states : "... you must force merging and repartitioning of the query by calling IsParallel() again within the query:" The name of the method is incorrect. The sentence should state : "... you must force merging and repartitioning of the query by calling AsParallel() again within the query:" The name of the method in bold face in the code just below this sentence is correct.

JimboT  Feb 22, 2011  Jun 03, 2011
Printed
Page 930
Just after Using Asynchronous Methods

Let’s rite a simple should probably be Let’s write a simple

Note from the Author or Editor:
Change "rite" to "write". ;)

Vincent Croquette  Mar 09, 2011  Jun 03, 2011
Printed
Page 936
Code listing, half way down page

The Read() method needs two edits: 1. The third parameter should be _bytesReader instead of 0 2. ContinueWith should be called with TaskContinuationOptions.NotOnFaulted|TaskContinuationOptions.AttachedToParent Here's how the method should read: void Read() // This will create a child task. { Task<int> readChunk = Task<int>.Factory.FromAsync ( _stream.BeginRead, _stream.EndRead, _data, _bytesRead, _data.Length - _bytesRead, null, TaskCreationOptions.AttachedToParent); readChunk.ContinueWith (Write, TaskContinuationOptions.NotOnFaulted | TaskContinuationOptions.AttachedToParent); } The same error is repeated on page 939 and should be fixed in exactly the same way. Note that these examples have been fixed on the companion web site - and also the "asychronator" sample project.

Note from the Author or Editor:
If you're unsure how it should look, examine the code listings on the following page: http://www.albahari.com/nutshell/cs4ch23.aspx Look for the listing "Non-blocking server: with Tasks" and "Writing async methods". I've highlighted the changes in purple. Note that the third parameter should be _bytesRead, not _bytesReader - or 0. Joe

Joseph Albahari
Joseph Albahari
O'Reilly Author 
Jan 31, 2010  Mar 01, 2010
Printed
Page 1018
Index

resurrection is misprinted as resueection

Gorpik  Apr 05, 2010  Jun 03, 2011
Printed
Page 1022
ToLookup

"ToLookup query opperator" needs to be "ToLookup query operator"

BrettS  Apr 04, 2010  Jun 03, 2011