Errata

C# 5.0 in a Nutshell

Errata for C# 5.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.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
?
Asynchronous Functions in C# 5.0 - Parallelism

The whole section about parallelism with asynchronous function is unclear. The sentence "Methods above this in the call stack will be subject to true concurrency only if the operation was initiated without a synchronization context present" is ambiguous.

True concurrency will occur only once the first 'await' statement is reached in the call tree. All the code executed before that will run on the caller's thread. That means that the example you give (adding _x++ *before* the await in GetAnswerToLife() is safe regardless the code is run with a synchronisation context or not. It would be different if _x++ would be *after* the await.

The way you present parallelism seem to mean that as soon as you don't await on an async function, it runs own thread.

Thierry Pauly  Jul 30, 2014 
Printed, PDF 2nd Paragraph under "How to Stringly Name an Assembly"

The paragraph references "MyApp.snk" when it should actually reference "MyKeyPair.snk" which is the file included in the sn.exe command line directly prior.

Kaleb Pederson  Jun 02, 2015 
Mobi Page 1
end of sentences

The mobi edition drops off the last character or two of the sentence very frequently on Amazon Kindle hardware. It makes reading difficult, and in some places the content becomes completely useless. For example, in Chapter 2, "Special Float and Double Values," the column that contains the values displays the correct value only on the first row (NaN). The second row displays only a +, and the third and fourth rows have blank entries.
Verified on a Kindle Fire (original, not HD) and a Paperwhite. This problem does *not* occur using the Kindle application v1.10.3 on a Mac.

Brian Hanafee  May 05, 2013 
PDF Page 2
Last 2 llines in code example on the page under header TimeZone

//True and //False after each Console.WriteLine should change from
Console.WriteLine (zone.IsDaylightSavingTime (dt1)); // True
Console.WriteLine (zone.IsDaylightSavingTime (dt2)); // False

to
Console.WriteLine (zone.IsDaylightSavingTime (dt1)); // False
Console.WriteLine (zone.IsDaylightSavingTime (dt2)); // True

Anonymous  Dec 04, 2013 
PDF Page 3
Platform Support topic

In the "Platform Support", the author comment about C# been used to write cross-platform code in the following cenarios: ASP.NET (generating HTML to run in browsers), Mono project (Linux, Mac OS X, Solaris, and Windows), and the passing Silverlight (Windows, and Mac OS X).

Is important to comment about the Xamarin (xamarin.com) initiative to create iOS, Android and Mac apps in C#.

Another important cross-platform capacity of C# is the new possibility to develop Windows Store apps with XAML to run in Windows 8 (x86, and x64 architectures) and Windows RT (ARM architecture).

Rog?rio Moraes de Carvalho  Apr 06, 2013 
PDF Page 4
last but one

"The CLR is language-neutral, allowing developers to build applications in multiple languages (e.g., C#, Visual Basic .NET, Managed C++, Delphi.NET, Chrome .NET,
and J#).

Chrome.NET, I've never heard about it and couldn't find any reference online. Also there's no mention of F#, maybe there'a typo of some sort?

Anonymous  Sep 13, 2012 
PDF Page 4
Last but one paragraph

Is important to inform the developer about the retirement of J# language and Java Language Conversion Assistant from future versions of Visual Studio, since Visual Studio 2005.

As another comment, I cannot find any information of a "Chrome .NET" language that can run on CLR, and I think that the book cannot omit the F# language, that is supported in Visual Studio 2012.

Rogerio Moraes de Carvalho  Apr 06, 2013 
PDF Page 5
2nd and 3rd paragraphs

2nd paragraph:
Microsoft has deprecated the use of "Metro-style applications" in favor of "Windows Store apps" or "Modern apps". And the "Microsoft application store" is called "Windows Store".

3rd paragraph:
The "Metro user interface" is now called "Modern User Interface" by Microsoft.

Rogerio Moraes de Carvalho  Apr 06, 2013 
PDF Page 12
1st paragraph

The csc.exe compiler is not located in the path
"%SystemRoot%\Microsoft.NET\Framework\<framework-version>"

The right path in which csc is located is
"%SystemRoot%\Windows\Microsoft.NET\Framework\<framework-version>"

Roy Ramos  Mar 13, 2015 
PDF Page 14
1st paragraph

The following book paragraph information is not according to the C# Language Specification Version 5.0:
"With contextual keywords, ambiguity cannot arise within the context in which they are used."

According to the specification: "a contextual keyword can conflict with declared names. In such cases, the declared name takes precedence over the use of the identifier as a contextual keyword."

Rogerio Moraes de Carvalho  Apr 07, 2013 
PDF Page 18
"The public keyword" topic

The following fragment is not correct: "The public keyword exposes members to other classes. In this example, if the Name
field in Panda was not public, the Test class could not access it. Marking a member".

In the example, the field can be "internal" to be accessed, once the "Panda" class is in the same assembly of the Test class.

The following fragment is not completely correct: "Marking a member public is how a type communicates: "Here is what I want other types to see - everything else is my own private implementation details?."

Members not marked as "public" (i.e. "protected", "internal", or "internal protected") are not necessarily "private". It can be accessed by other types in special circumstances.

Rogerio Moraes de Carvalho  Apr 08, 2013 
PDF Page 21
Figure 2-4

The value of Y should be 0.

Bhavesh  Sep 09, 2015 
PDF Page 28
Table of bitwise operators


0xf0 & 0x33 = 0x30
SHOULD BE:
0xf0 & 0x33 = 0x03
OR
0xf0 & 0x33 = 0x3

I think :).
I mean I'm pretty sure.

OK. Now I'm certain because I just used scientific mode in calc.

Bhavesh  Aug 29, 2012 
PDF Page 28
Table of bitwise operators


My apologies. I just realized my mistake. I think I left out last zero just like leading 0x when using calc :).

Sorry again.
It's a great book.

Bhavesh  Aug 31, 2012 
Printed Page 43
swap example

The following code does not compile:

class test
{
void Swap(ref string a, ref string b)
{
string temp = a;
a=b;
b=temp;
}
}

void Main()
{
string x = "Penn";
string y = "Teller";
Swap(ref x, ref y);
Console.WriteLine(x);
Console.WriteLine(y);
}

Change to:

void Swap(ref string a, ref string b)
{
string temp = a;
a=b;
b=temp;
}

void Main()
{
string x = "Penn";
string y = "Teller";
Swap(ref x, ref y);
Console.WriteLine(x);
Console.WriteLine(y);
}

You don't need the class declaration.

Anonymous  Jun 04, 2014 
Printed Page 50
Shift Category of Operator Table

How it is shown in my book:
<< Shift Left x >> 1
>> Shift Right x << 1

Shift left has an example for Shift right and Shift right has an example for Shift left.

See:
http://msdn.microsoft.com/en-us/library/xt18et0d.aspx
http://msdn.microsoft.com/en-us/library/a1sway8w.aspx

Anonymous  Sep 23, 2014 
PDF Page 50
Shift operator description

Shift operators << & >> are wrong in example column.

Bhavesh  Sep 27, 2015 
PDF Page 60
Last lines

I wouldn't use inheritance syntax while talking about name scoping. Inheritance has not been introduced yet and could confuse the reader.

(great book by the way :))

Marco Giannantonio  Sep 13, 2012 
PDF Page 68
The readonly modifier

For a first time c# reader it is not clear how readonly is different from const. It should be clarified here.

Marco Giannantonio  Sep 13, 2012 
PDF Page 78
Static constructors and field initialization order

I'm not sure about what the author is trying to show in his 2nd exemple:
class Program
{
static void Main() { Console.WriteLine (Foo.X); } // 3
}
class Foo
{
public static Foo Instance = new Foo();
public static int X = 3;
Foo() { Console.WriteLine (X); } // 0
}
If we swap the two lines in boldface, the example prints 3 followed by 3.

shouldn't it be more something like:
if we use a static constructor (static Foo()) instead of a non-static constructor (Foo()), the exemple prints 3 followed by 3 ?

That way we showed that a static constructor makes the static field initializers happen before the static constructor as stated in the first sentence of the paragraph?
Also, with a static Foo() there would be no need to create an instance of it, showing that the static constructor is effectively triggered by Foo.X in Main(), which is not the case with a non-static constructor (it would just prints 3).

But then the following sentence:
This means that the presence of a static constructor may cause field initializers to execute LATER in the program than they would otherwise.

should read:
This means that the presence of a static constructor may cause field initializer to execute EARLIER in the program than they would otherwiser.

well I'm a little confuse.

Anonymous  Jun 13, 2014 
PDF Page 100
2nd section

It says:
• The subclass has no way to call the base class method.

I tried & casting "this" to IUndoable worked.

Bhavesh  Oct 09, 2015 
PDF Page 101
Writing a class versus an interface

I think that one of the most hard things to teach regarding Object Orientation is explaining what an interface is and why it should be used instead of normal subclassing.

Worst thing one can do is saying that interfaces are there because the language disallows multiple inheritance.

That's not what interfaces are all about. I think this part of the book could be improved.

Marco Giannantonio  Sep 13, 2012 
Printed Page 114
Last paragraph

Near the bottom of the page (Covariance section) words seem to be missing after "for", or "for" is superfluous. The sentence reads:

"From C# 4.0, generic interfaces permit covariance for (as do generic delegates--see Chapter 4), but generic classes do not."

Harry de Boer  Jun 24, 2013 
PDF Page 116
2 after : Interface

You said:
The out modifier on T indicates that T is used only in output positions (e.g., return
types for methods). The out modifier flags the interface as covariant and allows us
to do this:
var bears = new Stack<Bear>();
bears.Push (new Bear());
// Bears implements IPoppable<Bear>. We can convert to IPoppable<Animal>:
IPoppable<Animal> animals = bears; // Legal
Animal a = animals.Pop();
The cast from bears to animals is permitted by the compiler—by virtue of the
interface being covariant. This is type-safe because the case the compiler is trying to
avoid—pushing a Camel onto the stack—can’t occur as there’s no way to feed a Camel
into an interface where T can appear only in output positions.

I can't understand why you use the class Camel, i try and i no find problem! sorry for my english

Juin François  Oct 23, 2014 
Printed Page 122
last sentence

When an instance method is assigned to delegate object, ...

should be

... to a delegate object, ...

Gary Meyers  Jan 11, 2014 
PDF Page 127
all the paragraph

I think that the chosen terms about delegates could be improved, because as they are used now could lead to confusion even for an expert.

I would call this:
delegate object ObjectRetriever();
a (non-generic) delegate declaration - not just "delegate".

Then I would call this:
static string RetriveString() { return "hello"; }
a (non-generic) delegate instance method (or delegate static method if it's static).

Then this:
ObjectRetriever o = new ObjectRetriever (RetriveString);
or
ObjectRetriever o = RetriveString;
a delegate instantiation.

Finally I would call this:
object result = o();
a delegate call or invocation.

I would avoid to use the term "target" (like in the ? Return type compatibility) because that could make confusion with the System.Delegate.Target and the general use of the term "delegate" without specifying if it's a declaration, method, assignment or invocation.



Marco Giannantonio  Sep 14, 2012 
Printed Page 127
Code example in Return type compatibility

RetriveString should be RetrieveString

Harry de Boer  Jul 08, 2013 
Other Digital Version 143
End of "The catch clause"

"In C++, it is possible (though not recommended) to throw an
object that does not derive from Exception."

Shouldn't "C++" be "C#"? The "Exception" class is a C# class.


Found on the google books page:
http://books.google.co.jp/books?id=EvXX03I5iLYC&printsec=frontcover&hl=ja#v=onepage&q&f=false

Anonymous  Apr 03, 2014 
Printed Page 144
.

Page 144

The following:
using (StreamReader reader = File.OpenText ("file.txt"))
{
...
}
is precisely equivalent to:
StreamReader reader = File.OpenText ("file.txt");
try
{
...
}
finally
{
if (reader != null)
((IDisposable)reader).Dispose();
}
/
------------------------------------------------------------------------
//but it's actually
/is precisely equivalent to:
{
StreamReader reader = File.OpenText ("file.txt");
try
{
...
}
finally
{
if (reader != null)
((IDisposable)reader).Dispose();
}
/} */// to create a scope of the local variable /**/StreamReader/*

The using statement introduces its own block for scoping purposes. This
arrangement means that the variable you declare in a using statement automatically goes out of scope at the end of the embedded statement and you cannot accidentally attempt to access a disposed resource

Anonymous  Dec 26, 2012 
Printed Page 150
1st paragraph

...but the calee's state...

should be:

...but the caller's state...

Alexandro Coutinho  Apr 20, 2014 
PDF Page 156
First line

Why is there + twice in the operator list?

Bhavesh  Oct 20, 2012 
PDF Page 159
In the example code that defines the Note struct

In the definition of the Note struct, the "value" member must either be declared public, or it needs a corresponding public property so that it may be correctly accessed as a member of the parameter "x" in the following example code on page 160:

public static implicit operator double (Note x)
{
return 440 * Math.Pow (2, (double) x.value / 12 );
}

As written, "value" is not an accessible member of "x" because the accessibility of "value" is not specified in the definition of "Note". Therefore, "value" would assume the default accessibility of any non-modified member of a struct - private.

Clark Bedsole  Jan 20, 2014 
PDF Page 159
Many places in the entire page

I'm pretty sure you meant overload wherever you've written override
on the page.

Bhavesh  Nov 16, 2015 
PDF Page 164
3rd line above section header "Anonymous Types"

The code below worked. It shouldn't according to following in the book:

To call ObjectHelper?s IsCapitalized method, we must specify it explicitly:
bool test2 = (ObjectHelper.IsCapitalized ("Perth"));

Am I missing something?

using System;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s = "Hi,";
Console.WriteLine(s.IsCapitalized());
object o = new object();
Console.WriteLine(o.IsCapitalized());
Console.ReadLine();
}
}
static class StringHelper
{
public static bool IsCapitalized(this string s)
{
if (string.IsNullOrEmpty(s))
return false;

return char.IsUpper(s[0]);
}
}
static class ObjectHelper
{
public static bool IsCapitalized(this object s)
{
if (s == null || s.ToString().Length == 0)
return false;

return !char.IsUpper(s.ToString()[0]);
}
}
}

Bhavesh  Oct 27, 2012 
PDF Page 164
Just above "Anonymous Types" section

In the line:
bool test2 = (ObjectHelper.IsCapitalized ("Perth"));

Wrapping call of ObjectHelper.IsCapitalized in parentheses is
unnecessary.

Also, the statement:
To call ObjectHelper’s IsCapitalized method, we must specify it explicitly:

Is wrong since following works just fine.
bool test2 = ((object)"Perth").IsCapitalized();

Bhavesh  Nov 22, 2015 
Printed Page 176
Code in the bottom half of the page

The class Foo implements the interface INotifyPropertyChanged. However, the type of the particular event handler is missing, as well as the semicolon at the end of the line.

It says:
public event PropertyChanged = delegate { }

Instead, it should be:
public event PropertyChangedEventHandler PropertyChanged = delegate { };

Markus Schmidt  Oct 07, 2015 
Printed Page 183
Second bulleted sentence

Third-party tools (such as Sandcastle and NDoc) can transform XML file...

should be

...transform the XML file...

Gary Meyers  Jan 19, 2014 
Printed Page 193
Last sentence in the Application Domains paragraph

The AppDomain type is defined in the System namespace...

should be

...type that is defined...

Gary Meyers  Jan 19, 2014 
Printed Page 209
the animal track paragraph

This means string's CompareTo defines the default ordering behavior strings, in...

should be

...behavior of strings, in...

Gary Meyers  Jan 21, 2014 
Printed Page 211
middle

A text encoding can restrict what characters can be represented, as well as impacting storage efficiency.

would read more clearly as something like

A text encoding can restrict what characters may be represented and also affect the efficiency of the data storage.

Gary Meyers  Jan 21, 2014 
Printed Page 220
The last sentence just above the warning symbol.

The reference to page 220 should be changed to page 227.

Steven Lin  Oct 29, 2014 
PDF Page 223
Top 2 lines

// 09:00:00 and // 08:00:00 should change places from
Console.WriteLine (zone.GetUtcOffset (dt1)); // 09:00:00
Console.WriteLine (zone.GetUtcOffset (dt2)); // 08:00:00

to

Console.WriteLine (zone.GetUtcOffset (dt1)); // 08:00:00
Console.WriteLine (zone.GetUtcOffset (dt2)); // 09:00:00

Anonymous  Dec 04, 2013 
PDF Page 223
In the code under the first sentence "The GetDaylightChanges method returns specific daylight saving..."

The output from the two first Console.WriteLine should change place from:
Console.WriteLine (day.Start); // 26/10/2008 2:00:00 AM (Note D/M/Y)
Console.WriteLine (day.End); // 30/03/2008 3:00:00 AM

to
Console.WriteLine (day.Start); // 30/03/2008 3:00:00 AM (Note D/M/Y)
Console.WriteLine (day.End); // 26/10/2008 2:00:00 AM

except: (Note D/M/Y) that can remain on the first line

Anonymous  Dec 04, 2013 
PDF Page 223
In the code under the first sentence "The GetDaylightChanges method returns specific daylight saving..."

The output from the two first Console.WriteLine should change place from:
Console.WriteLine (day.Start); // 26/10/2008 2:00:00 AM (Note D/M/Y)
Console.WriteLine (day.End); // 30/03/2008 3:00:00 AM

to
Console.WriteLine (day.Start); // 30/03/2008 3:00:00 AM (Note D/M/Y)
Console.WriteLine (day.End); // 26/10/2008 2:00:00 AM

except: (Note D/M/Y) that can remain on the first line

Anonymous  Dec 04, 2013 
PDF Page 223
In the code under the first sentence "The GetDaylightChanges method returns specific daylight saving..."

The DATE output (not the time) from the two first Console.WriteLine should change place from:
Console.WriteLine (day.Start); // 26/10/2008 2:00:00 AM (Note D/M/Y)
Console.WriteLine (day.End); // 30/03/2008 3:00:00 AM

to
Console.WriteLine (day.Start); // 36/10/2008 2:00:00 AM (Note D/M/Y)
Console.WriteLine (day.End); // 30/03/2008 3:00:00 AM

except: (Note D/M/Y) that can remain on the first line
AND the hours should remain the same

Anonymous  Dec 04, 2013 
Printed Page 224
2nd complete paragraph

The term "DateZoneInfo" should be "TimeZoneInfo"

Rob Siklos  May 20, 2014 
Printed Page 230
1st paragraph under heading "Composite formatting"

'we illustrated this in "String and Text Handling" on page 201'

should be changed to

'we illustrated this in "String.Format and composite format strings" on page 206'

Steven Lin  Oct 29, 2014 
Printed Page 233
At the bottom

At the bottom of page 233 (table 6-2 Standard numeric format strings), the last 2 entries for column 'Sample Input' should be 1-2 rows lower, so they line up properly with the 'Result' column.

Philip Brown  Nov 14, 2012 
PDF Page 237
the last 2 rows in table 6-4

The last two rows (added one column for actual output)
Format str Meaning Sample output Actual output
m, M Month and day January 02 18 1
y, Y Year and month 2000 January 0 1


To get the sample output, the format strings needs to change to:
MMMM dd Month and day January 02
yyyy MMMM Year and month 2000 January

Anonymous  Dec 05, 2013 
Printed Page 242
First sentence in the XmlConvert section

If you're dealing with data that's originated from or destined for an XML file, XmlConvert (the System.Xml namespace) provides...

should be

...file, XmlConvert (in the System.Xml...

Gary Meyers  Jan 23, 2014 
PDF Page 245
Table 6-7, Task "Lossless numeric conversion"

The example for Task "Lossless numeric conversion" has an example:
int i = 23;
double d = d;

I think this should be changed to:
int i = 23;
double d = i;

Anonymous  Dec 06, 2013 
Printed Page 245
the animal track paragraph

I think

This is concerned more about localization: we cover this in Chapter 18.

should be

This is concerned more with localization; we cover this in Chapter 18.

Gary Meyers  Jan 23, 2014 
Printed Page 253
Second sentence in the Comparing Tuples section

In keeping with this comparing two distinct instances...

would read more clearly with a comma

In keeping with this, comparing...

Gary Meyers  Jan 23, 2014 
PDF Page 256
Chapter 6 the virtual object.equals method

"with structs, Equals performs structural comparison by calling Equals on each of its fields."

Although it is acceptable, it is not accurate/informative enough.

"If none of the fields of the current instance and obj are reference types, the Equals method performs a byte-by-byte comparison of the two objects in memory. Otherwise, it uses reflection to compare the corresponding fields of obj and this instance."

Quoted from MSDN: http://msdn.microsoft.com/en-us/library/2dts52z7.aspx

colin fang  Jul 10, 2013 
Printed Page 268
the animal track paragraph

In a Visual Studio WPF and Windows Forms applications, the...

should be

In Visual Studio WPF and...

Gary Meyers  Jan 27, 2014 
Printed Page 272
the largest paragraph

Reset exists mainly for COM interop: calling it directly...

should be

...COM interop; calling...

Gary Meyers  Jan 27, 2014 
Printed Page 279
last sentence before the animal tracks paragraph

Of course, a collection class itself is free to implement both versions of an interface if beneficial (which, often, it is).

would read more naturally without the commas:

...both versions of an interface if beneficial (which it often is).

Gary Meyers  Jan 27, 2014 
ePub Page 285
United States

On Page 285 of C# In A Nutshell (Constructing and Indexing, Arrays), you write:

The static GetValue and SetValue methods let you access elements in a dynamically created array...

In my VS, GetValue and SetValue don't seem to be static methods of the Array class. Am I looking in the wrong place?

RON

Ron  Dec 02, 2014 
PDF Page 289
last line of code

reads:
// numbers array is now { 3, 5, 1, 2, 4 }

should be:
// numbers array is now { 1, 3, 5, 2, 4 }

Anonymous  Jun 26, 2014 
ePub Page 289
Before the last paragraph

int[] numbers = { 1, 2, 3, 4, 5 };
Array.Sort(numbers, (x, y) => x % 2 == y % 2 ? 0 : x % 2 == 1 ? -1 : 1);
// numbers array is now {3, 5, 1, 2, 4}

When I ran it on Visual Studio 2013, I got output as {1, 3, 5, 2, 4} not {3, 5, 1, 2, 4}

Amine G.  Jun 01, 2015 
Printed Page 306
First sentence in the Collection<T> and CollectionBase section

Collection<T> class is a customizable wrapper for List<T>.

should be

The Collection<T> class is...

Gary Meyers  Jan 27, 2014 
Printed Page 312
last sentence before the IEqualityComparer and EqualityComparer section

...which allow the option of structural comparisons on such as classes and arrays.

should be something like

...comparisons on entities such as...

Gary Meyers  Jan 27, 2014 
Printed Page 318
second paragraph

We can demonstrate this using arrays and tuples, which implement these interfaces: in the following example, we compare two arrays for equality: first using the default Equals method, then using IStructuralEquatable's version:

would read more clearly as two sentences with just one colon

We can demonstrate this using arrays and tuples, which both implement these interfaces. In the following example, we compare two arrays for equality, first by using the default Equals method and then by using IStructuralEquatable:

Gary Meyers  Jan 27, 2014 
Printed Page 331
first paragraph

In SQL, you reference a table alias in the SELECT clause before defining it in a FROM clause.

should be

In SQL, you can reference...

because it is not a technique that is utilized in every SELECT clause.

Gary Meyers  Jan 31, 2014 
Printed Page 334
first paragraph

...the query will honor the value of the those variables...

should delete the 'the' to make

...value of those variables...

Gary Meyers  Jan 31, 2014 
Printed Page 352
Bottom of the page, select sample

SELECT UPPER(Name) FROM Customer ORDER BY UPPER(Nome)

I think the "UPPER" is redundant...

Alexandro Coutinho Alves  Apr 29, 2014 
Printed Page 352
middle to bottom of page

This is in chapter 8 "LINQ Queries", subsection "Combining Interpreted and Local Queries".

The sequence of query operators in the initialization of q does not match up with the explanation given in the paragraph below it on the page.

Since the equivalent SQL statement at the bottom of the page matches the given sequence of query operators, the explanation in the paragraph should probably be changed somehow. Something like this:

(Edits in double asterisks)

---
Because customers is of a type implementing IQueryable<T>, the Select operator resolves to Queryable.Select. This returns an output sequence also of type IQueryable<T>, **so the OrderBy operator similarly resolves to Queryable.OrderBy.** But the next query operator, Pair, has no overload accepting IQueryable<T>---only the less specific IEnumerable<T>. So, it resolves to our local Pair method---wrapping the interpreted query in a local query. Pair also emits IEnumerable**<T>**, so **the second Select** wraps another local operator.
---

William Rummler  Jun 09, 2014 
Printed Page 357
next to last sentence

You can then obtain a queryable object calling GetTable...

should be

...object by calling...

Gary Meyers  Feb 03, 2014 
Printed Page 361
first paragraph in the Associations section

For example, suppose we define a customer and purchase table in a one-to-many relationship:

would be clearer that there are two tables with plural wording

For example, suppose that we define customer and purchase tables in a one-to-many relationship:

Gary Meyers  Feb 04, 2014 
Printed Page 371
top of page, in tracks-box call-out

To demonstrate that lambda expressions with statement bodies cannot be converted to expression trees, the following example is provided:

Expression<Func<Customer, bool>> invalid = { return true; }

When compiled, this gives two errors:

Error 1 Invalid expression term 'return'
Error 2 { expected

It seems like the following example was intended:

Expression<Func<Customer, bool>> invalid = c => { return true; };

This gives a more relevant error:

Error 1 A lambda expression with a statement body cannot be converted to an expression tree

William Rummler  Jun 12, 2014 
PDF Page 406
3rd heading

on page 378, it says:
Grouping
IEnumerable<TSource> →IEnumerable<IGrouping<TSource,TElement>>

this should be:
Grouping
IEnumerable<TSource> →IEnumerable<IGrouping<TKey,TElement>>
since the resulting grouping is based on the keySelector.

The same mistake is on page 406 under the Grouping heading.

Anonymous  Jun 28, 2015 
Printed Page 421
last two paragraphs

The text states,

"Range and Repeat work only with integers."

and,

"Repeat accepts the number to repeat, and the number of iterations."

It's not true that Repeat works only with integers. It's a generic method accepting a type parameter for the type of its first argument (the element to repeat).

See Enumerable.Repeat at MSDN:

http://msdn.microsoft.com/en-us/library/bb348899(v=vs.110).aspx

William Rummler  Jun 24, 2014 
Mobi Page 445

in the LINQ to XML namespace examples, in the paragraph explaining that a prefixed element does not define a default namespace for descendants, the sample xml has a typo.
It has nut:xmlns="OReilly... where it should be xmlns:nut="OReilly...

Richard Potter  Sep 03, 2013 
PDF Page 460
Code sample

ProhibitDtd is obsolete.It should be replaced in row 3 of the code example:
settings.ProhibitDtd = false; // Must set this to read DTDs

with:
settings.DtdProcessing = DtdProcessing.Parse; //Must set this to read DTDs

Anonymous  Jan 12, 2014 
Printed Page 474
middle

This sentence ---

"The ChildNodes property (defined in XNode) allows you to descend into the tree structure."

--- should be ---

"The ChildNodes property (defined in XmlNode) allows you to descend into the tree structure."


XNode does not have a ChildNodes property and was discussed in an earlier section. XmlNode has this property, is part of the XmlDocument DOM under discussion, and is a base class for XmlElement, the return type of the DocumentElement property of XmlDocument (referenced in the text's following code snippet).

William Rummler  Jul 30, 2014 
Printed Page 478
Bottom half

This is the second example under "Common XPath Operators":

---
The / symbol queries child nodes. To select the customer nodes:
XmlNode node = doc.SelectSingleNode ("customers/customer");
---

The example's lead-in text implies that more than one node will be selected, but the snippet only selects one node.

Either (a) the text should be changed to something like "To select the first customer node:"

Or (b) the example snippet should be changed to something similar to the other examples, e.g.

"XmlNodeList nodes = doc.SelectNodes ("customers/customer");

William Rummler  Aug 13, 2014 
Printed Page 478
Bottom half

This is the fourth example under "Common XPath Operators":

---
The .. operator selects parent nodes. This example is a little silly because we're starting from the root anyway, but it serves to illustrate the functionality:

XmlNodeList nodes = doc.SelectNodes ("customers/customer..customers");
---

The example does not illustrate proper usage of the .. operator, since the given snippet will select all child nodes of customers having the element name "customer..customers". Against the previous page's XML, this XPath query selects nothing.

First, this example's lead-in text should describe the intended result of the query (as the other examples in this subsection do). Something like "[...] serves to illustrate the functionality by selecting the customers element after navigating to one of its children:".

Second, the snippet should properly demonstrate the .. operator, e.g. coinciding with the above:

XmlNodeList nodes = doc.SelectNodes ("customers/customer/..");

William Rummler  Aug 13, 2014 
Printed Page 479
second paragraph in the XPathNavigator section

Spawn instances of XPathNavigator from an...

would read more clearly with something like

You can spawn instances of XPathNavigator...

Gary Meyers  Feb 07, 2014 
Printed Page 479
second paragraph in the XPathNavigator section

Here is an example of spawning an XPathNavigator from an XmlDoument:

should be

...from an XmlDocument:

Gary Meyers  Feb 07, 2014 
Printed Page 484
next to last paragraph

XmlTransform works very simply:

should be

XslCompiledTransform works very simply:

Gary Meyers  Feb 07, 2014 
PDF Page 489
definition of HouseManager class

In the definition of the HouseManager class the constructor is named "Demo" instead of "HouseManager".

chosenbreed  Dec 19, 2014 
Printed Page 499, 500
Bottom p. 499

Footnote 2, cited at the bottom of page 499, is actually located on page 500.

The footnote should probably be located on the same page on which it is cited.

William Rummler  Aug 18, 2014 
PDF Page 507
Target getter

The whole getter looks strange and slightly broken. Why keep track of dead references and not remove them immediately if we iterate over a copy of '_targets'? Why check if 'target' is null if it is never null? And the garbage collectior can collect mt.Refernce.Target after the mt.Refernce.IsAlive check but before the delegate construction, so the target method will be called with 'this' set to null, which is sort of bad. Proposed fix:
get {
Delegate result = null;
foreach (var mt in _targets.ToArray()) {
object target = mt.Reference.Target;
if (target == null) {
_targets.Remove(mt);
} else {
result = Delegate.Combine(result,
Delegate.CreateDelegate(typeof(TDelegate), target, mt.Method));
}
}
return result as TDelegate;
}

KhanFusion  Jan 02, 2013 
Printed Page 521
code example at the bottom

To make it clearer that there are other lines of code that would be inserted, as is done in other code examples in the book, there should be an ellipsis in this example.

public static int Parse (string s)
{
Contract.Requires (s != null);
...
}

Gary Meyers  Feb 28, 2014 
PDF Page 522
First code sample

There is no overload of ObjectDisposedException(); that takes 0 arguments as in the example:
if (_isDisposed) // _isDisposed is a private field
throw new ObjectDisposedException();
...
It needs at least the name a string containing the name of the disposed object (string objectName).

Had the objectName already been added to the example it may have distracted more than not.

Anonymous  Jan 03, 2014 
Printed Page 525
last paragraph

Occasionally, it's useful to ensure that a certain condition holds should a particular type of exception be thrown.

would read more clearly with something like

Occasionally, it's useful to ensure that a certain condition is true before a particular type of exception is thrown.

Gary Meyers  Feb 28, 2014 
Printed Page 528
second paragraph

In that method, call Contract.Invariant to enforce each condition that should hold true if your object is a valid state:

should be

...your object is in a valid state:

Gary Meyers  Feb 28, 2014 
PDF Page 530
First sentence

The first sentence states:
If you don?t specify /throwonfailure?or check ?Assert on Contract Failure??a
dialog appears upon contract failure, allowing you to abort, debug or ignore the
error.

Another sentence further down on the page (after the second "cat fot steps") states:
If you specify the /throwonfailure switch?or uncheck ?Assert on Contract Failure?
in Visual Studio?a ContractException is thrown upon failure.

The second sentence is clear in that if the switch ?Assert on Contract Failure? is unchecked there will be thrown a ContractException, aka no dialog will be shown.

The first sentence can in my opinion be interpreted as
If you don?t specify /throwonfailure?or DON'T check ?Assert on Contract Failure?...
followed by "a
dialog appears upon contract failure"
which is then incorrect since an unchecked "Assert on Contract Failure" throws a ContractException as the second sentence clearly states.

Anonymous  Jan 04, 2014 
PDF Page 530
First sentence

The first sentence states:
If you don?t specify /throwonfailure?or check ?Assert on Contract Failure??a
dialog appears upon contract failure, allowing you to abort, debug or ignore the
error.

It perhaps should read:
If you don?t specify /throwonfailure?or uncheck ?Assert on Contract Failure??a
dialog appears upon contract failure, allowing you to abort, debug or ignore the
error.

Anonymous  Jan 04, 2014 
Printed Page 533
First sentence in the Static Contract Checking section

Code contracts permit static contract checking, whereby a tool...

would be clearer about who is doing what with something like

Code contracts make static contract checking possible, whereby a tool...

Gary Meyers  Feb 28, 2014 
Printed Page 533
next to last paragraph

You can run Microsoft's static contracts tool either from the command-line via ccheck, ...

should be

...from the command line via ccheck, ...

Gary Meyers  Feb 28, 2014 
Printed Page 550
the paragraph above the animal tracks paragraph

Thread.Yield() method does the same thing - except that it relinquishes only to threads running on the same processor.

should be

Thread.Yield() does the same thing, except that it...

Gary Meyers  Feb 28, 2014 
Printed Page 562
Example on lower page

From reading about SynchronizationContext usage, the example on page 562 seems wrong.

When the UI thread starts the worker thread, I think it needs to send a reference of _uiSyncContext to the worker thread like:

new Thread(Work).Start(_uiSyncContext);

Then the worker thread can do the _uiSyncContext.Post, but even that code seems strange.

The Post has a lambda of (_ => txtMessage.Text = message);
Seems after the opening '(' the '_' character is wrong. Perhaps it should be () ?

Philip Brown  Apr 12, 2013 
Printed Page 562
Example on lower page

Follow-up on my previous post:

The UI thread does not have to pass the _uiSyncContext to the worker thread in this case. Both threads can share the same reference to _uiSyncContext.

But the lambda example in the Post method remains as a question.

Philip Brown  Apr 12, 2013 
Printed Page 566
the paragraph above the animal tracks paragraph

(Notice, however, that we didn't call Start because Task.Run creates "hot" tasks; ...

It is not clear where you didn't call Start because the most recent code example,

new Thread (() => Console.WriteLine ("Foo")).Start();

does call Start. If you mean Task.Start in the example before the most recent example, you should say Task.Start instead of just Start.

Gary Meyers  Feb 28, 2014 
Printed Page 570
next to last paragraph

ContinueWith is particularly useful in parallel programming scenarios; we cover it in detail in "Continuations" on page 569 in Chapter 23.

should be

...on page 942 in Chapter 23.

Gary Meyers  Feb 28, 2014 
Printed Page 572
second paragraph

We can write this without a thread through use the Timer class, ...

should be something like

...without a thread by using the Timer class, ...

Gary Meyers  Jan 06, 2015 
Printed Page 572
third paragraph

By attaching a continuation to the task, we can write its result without any blocking any thread:

should be

...result without blocking any thread:

Gary Meyers  Jan 06, 2015 
Printed Page 574 to 593
various

I disagree with the book's multiple, awkward attempts at creating new nouns with "thread-safety" and "thread-efficiency". "thread safety" and "thread efficiency" would be more readable and wouldn't jar the reader out of the flow of the text as they try to parse the extraneous dashes.

Gary Meyers  Feb 28, 2014 
Printed Page 576
1st full paragraph

"course-grained" should be "coarse-grained"

Rob Siklos  Mar 17, 2015 
Printed Page 578
first paragraph in the animal tracks section

...current local state of the method ("how many more times is this loop going to run?")

should end with a period

...going to run?").

Gary Meyers  Mar 01, 2014 
Printed Page 579
widowed partial snippet at top

There's a missing closing brace.

The last line of the snippet is

);

but should be

});

William Rummler  May 12, 2015 
Printed Page 580
second paragraph

...(implementing INotifyCompletion.OnCompleted and with a appropriately typed GetResult method...

should be

...and with an appropriately typed...

Gary Meyers  Mar 01, 2014 
PDF Page 597
General note

IObserver<T> does not have a "MoveNext" method. It should be "OnNext".

chosenbreed  Dec 17, 2014 
Printed Page 629
first paragraph in the Compression Streams section

I think that

...including a CRC to detect for errors.

would read more naturally as

...including a CRC to detect errors.

Gary Meyers  Mar 04, 2014 
PDF Page 634
Code sample (SupportsCompressionEncryption)

The code sample needs to import the System.ComponentModel namespace to get access to Win32Exception.

Joseph Eddy  Aug 29, 2012 
Printed Page 660
Example on lower page

In the example using DownloadFileTaskAsync, it involves:

Task.Delay(5000).ContinueWith (ant => wc.CancelAsync());

The comments above says 'canceling the download if it takes longer than 5 seconds'.

Since this time-out task always executes, the comments should say something like:

'the download is canceled after 5 seconds'.

Philip Brown  Apr 19, 2013 
Printed Page 660
Example on lower page

I think the example is OK after all.

Even though the cancel part is always attempted, that instance of the WebClient would have completed OK (normally), in which case the cancel does nothing (I think).

Philip Brown  Apr 20, 2013 
Printed Page 677
Example on lower page

The example for 'Writing an HTTP Server' involves a WebClient sending a request to a HttpListener. I tried that exact code several times but kept getting 'time out'. I am using VS2012 Framework 4.5 on Windows 8.

So then I tried using HTTPClient with HTTPRequestMessage and HTTPResponseMessage and it works fine! The HttpListener part was not changed.

Q: Does HttpListener only support HttpRequestMessages? The HttpListener class on MSDN says it 'responds to HTTP requests'.

Here is my modified code (which responds to a text box in WPF):

Uri address1 = new Uri("http://localhost:51111/MyApp/Request.txt");
var handler = new HttpClientHandler();
handler.UseProxy = false;

var client = new HttpClient(handler);

var request1 = new HttpRequestMessage(HttpMethod.Get, address1);
HttpResponseMessage response1 = await client.SendAsync(request1);

response1.EnsureSuccessStatusCode();
string result = await response1.Content.ReadAsStringAsync();
txtArea.Text = result;

Philip Brown  Apr 25, 2013 
PDF Page 679
Code sample (ProcessRequestAsync method)

The code sample needs "using System.Text;" to resolve "Encoding.UTF8.GetBytes"

Joseph Eddy  Aug 31, 2012 
PDF Page 685
Code sample

The "Result" of the sample program includes an output line consisting of just "Hello", but the sample program will not actually output that line.

My guess is that there is meant to be a "Console.WriteLine(msg);" in the Server() method after "string msg = ..."

Joseph Eddy  Aug 31, 2012 
Printed Page 750
Image XAML at bottom

The last <Image> example to refer to an image in another assembly has:
Source="UtilsAssembly;Component/flag.png"/>

The only way I could get that to work is to use:

Source="pack://application:,,,/UtilsAssembly;Component/flag.png"/>

Philip Brown  Apr 30, 2013 
Printed Page 750
1st paragraph

The command line compiler option to include a resource is "/resource", not "/resources".

Jason  Oct 04, 2015 
Printed Page 767
second paragraph in "Obtaining array types"

MakeArray can be passed an integer argument...

should be

MakeArrayType can be...

Gary Meyers  Mar 04, 2014 
Printed Page 776
top

I think GetMethod/ in table 19-1 should be GetMethod

Gary Meyers  Mar 04, 2014 
Printed Page 788
second paragraph

Reflection exposes psuedocustom attributes...

should be

...pseudocustom...

Gary Meyers  Mar 04, 2014 
Printed Page 830
1st paragraph

In the second line of the code snippet:

try { groupKey = d.Value); }

the closing parenthesis should be removed. Moreover, IGrouping<TKey, TElement> has no "Value" property. It should be

try { groupKey = d.Key; }

Michael Spranger  Mar 24, 2016 
Printed Page 877
2nd example, middle of page

2nd example does not provide a value for _val1 and _val2. Probably should be '1' like the 1st example above, so the division will work.

Philip Brown  May 13, 2013 
Printed Page 882
bottom paragraph

A better strategy is to be wary of locking around calling methods in objects...

might be clearer with something like

...around calls of methods in objects...

since "calling methods" often uses calling as an adjective instead of a verb.


This same suggestion applies to the next sentence:

Also, consider whether you really need to lock around calling methods in other classes...

Gary Meyers  Mar 08, 2014 
Printed Page 889
2 example sections at the bottom

Regarding the example of dealing with an immutable object, some questions.

1. In the 2nd from the bottom block of code, the block ends with:

lock (_statusLocker) _status = status; // Very brief lock

Q. What would normally be done once this is done? I would think to use the readonly fields from the _status reference, but that seems to be done in the next code block.

2. In the paragraph just above the last block of code it says:
'we first obtain a copy of the object...'

Perhaps that statement should be changed because of...

The code below has:

lock (_statusLocker) status = _status; // Again, a brief lock
int pc = status.PercentComplete;
etc.

Q: Isn't the code just getting a copy of the 'reference' to the object, not a copy of the object?
Q: After the lock, if the active thread is time sliced out and another thread gets control, could 'status' be changed to refer to a newer version of the immutable object?
If so, why both with the lock? Isn't having a reference to the immutable object good enough, so the code can reference the readonly fields of the immutable object as a relevant group, where the percent complete and string message still makes sense together, regardless if the immutable object has changed to a different version of the immutable object?

Philip Brown  May 14, 2013 
Printed Page 889
example sections at the bottom

Regarding my previous questions...

In the 3 related code blocks, there are local variables 'status' and '_status'.

Q. Are these local variables in a method?
Q. If so, won't each thread have their own copy of these variables?
Q. If so, why lock when referring to them?
Q. Why have these 2 variables? Isn't just 1 reference to the immutable object enough?

Philip Brown  May 14, 2013 
Printed Page 900
bottom paragraph

Rather than waiting on wait handle (and blocking...

should be

...on a wait handle...

Gary Meyers  Mar 08, 2014 
PDF Page 902
WaitAny, WaitAll, and SignalAndWait section

WaitHandle.SignalAndWait is described as atomic in the text, however according to Microsoft (cf. http://msdn.microsoft.com/en-us/library/system.threading.waithandle.signalandwait(v=vs.110).aspx and https://connect.microsoft.com/VisualStudio/feedback/details/619210/system-threading-waithandle-signalandwait-is-not-atomic ) SignalAndWait is *not* guaranteed to be atomic. This was changed from the original documentation that claimed it was atomic.

The Barrier class (cf. pg. 903) appears works to work correctly, probably because it's SignalAndWait is overridden.

Anonymous  Jan 28, 2014 
Printed Page 906
second bullet in the LazyInitializer section

It offers another mode of initialization that has multiple threads race to initialize.

would be clearer with something like

...initialization that has multiple threads racing to initialize.

or

...initialization in which multiple threads race to initialize.

Gary Meyers  Mar 08, 2014 
PDF Page 988
First sentence after the hreadline Embedding Interop Types

Change tlimp.exe in:

We said previously that C# ordinarily calls COM components via interop types that
are generated by calling the tlimp.exe tool (directly, or via Visual Studio).

to tlbimp.exe

Anonymous  Dec 12, 2013 
PDF Page 989
Second sentence after the headline Primary Interop Assemblies

Change tlimp.exe in:

This created a problem in that if two developers each ran the tlimp.exe tool on the same COM component...

to tlbimp.exe

Anonymous  Dec 12, 2013 
Printed Page 996
Third paragraph from the bottom.

"The following allows anything between cv and .doc and is equivalent to dir cv*.doc:"

The part about "is equivalent to" doesn't make sense to me. The word dir appears to be there by mistake. The * would indicate 0 or more lowercase v characters. The . would match any character besides newline.

But that's not equivalent to "cv.*\.doc", right?

Mark Carringer  Feb 17, 2017 
Printed Page 1026
United States

The Index entry for "internal access modifiers, 74" should instead point to page 94

Gary Meyers  Jan 09, 2014 
Printed Page 1033
bottom left

The Index entry for "private access modifiers, 74" should instead point to page 94

Gary Meyers  Jan 09, 2014 
Printed Page 1033
upper right

It seems redundant to have both of these entries in the index.

properties, 73
properties (C#), 73

Gary Meyers  May 20, 2014