Errata

C# 7.0 in a Nutshell

Errata for C# 7.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
ePub Page 2
TaskCompletionSource in Chapter 14(Concurrency and Asynchrony)

I noticed you use slave to describe the behavior of TaskCompletionSource, and I suggest alternatives like operative, worker or drone instead because the master-slave terminology is racially charged in the US.

Here are the instances I noticed.

“It works by giving you a “slave” task that you manually drive—by indicating when the operation finishes or faults.”

Additionally in the following example:

var tcs = new TaskCompletionSource<int>();

new Thread (() => { Thread.Sleep (5000); tcs.SetResult (42); })
{ IsBackground = true }
.Start();

Task<int> task = tcs.Task; // Our "slave" task.
Console.WriteLine (task.Result); // 42

Meredith Hoo  Aug 31, 2020 
Printed Page 25
1s paragraph in section "Values Types Versus Reference Types"

Is "Generic type parameters" a category of a C# type or do you mean "Generic type" as on page 122, 1st paragraph of section "Generic Types", you write that "A generic type declares type parameter - placeholder types to be filled in the consumer of the generic type, which supplies the type arguments".

Or is "Generic type" a "Reference type" ?

Jean Jacques Uzabumuhire  Jul 30, 2019 
Printed Page 42
Code after the 1st paragraph.

The code as illustrated does not span 2 lines. In order for the code to span 2 lines we can write :
string s = $@"this spans {x}
lines";

or :

string s = $@"this spans
{x} lines";

but not :

string s = $@"this spans {
x} lines";

Jean Jacques Uzabumuhire  Jul 29, 2019 
PDF Page 84
In 'Deconstructors (C# 7)' section's second paragraph

The error is in the following sentence: "A deconstruction method must be called Deconstruct, and have one or more out parameters, such as in the following class: "

The deconstructor method must have at least two out parameters to deconstruct to. Therefore "have one or more out parameters" part should be corrected.

Jonas Ložys  Mar 21, 2020 
Printed Page 129
1st line of code in the 2nd paragraph

Is it normal that I don't see a self-referencing generic declarations in the following code :

class Foo<T> where T : IComparable<T> { ... }

Jean Jacques Uzabumuhire  Jul 27, 2019 
Printed Page 143
2nd paragraph

In the second to last sentence, you say, "...Test can implement ITransformer only once," but the example does not have a Test class. Are you referring to Squarer and Cuber?

Daryl Lucas  Apr 08, 2019 
Printed Page 305
Count mehtod

The following code would return 4 instead of returning 6, because it strings implements IEnumerable<char>.

We could fix this issue by testing wether a given element is of type string :

public static int Count(IEnumerable e)
{
int count = 0;
foreach(object element in e)
{
if (element.GetType().Name == typeof(string).Name)
{
count++;
}
else
{
var subCollection = element as IEnumerable;
if (subCollection != null)
count += Count(subCollection);
else
count++;
}
}
}
return count;
}

Jean Jacques Uzabumuhire  Jul 24, 2019 
Printed Page 305
Count method code

The following code would return 4 instead of returning 6, because it strings implements IEnumerable<char> :

Count(new object[]
{
new int[] { 26, 27 },
new string[] { "aa", "bb" },
new char[] { 'a', 'b' }
})

We could fix this issue by testing wether a given element is of type string :

public static int Count(IEnumerable e)
{
int count = 0;
foreach(object element in e)
{
if (element.GetType().Name == typeof(string).Name)
{
count++;
}
else
{
var subCollection = element as IEnumerable;
if (subCollection != null)
count += Count(subCollection);
else
count++;
}
}
}
return count;
}

Jean Jacques Uzabumuhire  Jul 24, 2019 
Printed Page 305
Count method code

THIS THE CORRECT ERRATUM, OTHERS ON THE SAME ISSUE MAY BE SUPPRESSED, I APOLOGIZE FOR THE INCONVENIENCE.

The following code would return 8 instead of returning 6, because it strings implements IEnumerable<char> :

Count(new object[]
{
new int[] { 26, 27 },
new string[] { "aa", "bb" },
new char[] { 'a', 'b' }
})

We could fix this issue by testing wether a given element is of type string :

public static int Count(IEnumerable e)
{
int count = 0;
foreach(object element in e)
{
if (element.GetType().Name == typeof(string).Name)
{
count++;
}
else
{
var subCollection = element as IEnumerable;
if (subCollection != null)
count += Count(subCollection);
else
count++;
}
}
}
return count;
}

Jean Jacques Uzabumuhire  Jul 24, 2019 
PDF Page 547
Debugger Attributes in the Diagnostics Chapter

The DebuggerStepThrough and DebuggerHidden attributes provide suggestions to the debugger on how to handle single-stepping for a particular method, constructor, or class.

The above writes how DebuggerHidden can be used in structure, class, and methods. But this is an error. The error message is: "Attribute DebuggerHidden" is not valid on class type. It is only valid on 'constructor, method, property, indexer' declarations.

Nahid Jamalli  Aug 30, 2019 
Printed Page 568
The output in the second paragraph in section "Lambda expressions and captured variables"

When I ran the code example, the output for each thread is always 10 instead of being a number from 0 to 9.

Jean Jacques Uzabumuhire  Jul 01, 2019 
Printed Page 627
MemoryStream section, 1st paragraph

What does "Susing15" mean ?

Jean Jacques Uzabumuhire  Jul 15, 2019 
Printed Page 630
Code example for activating message transmission mode.

I am using .NET Core 2.2 on macOS, when I ran the code example with mono on the command line, I got this error :

"Unhandled Exception:
System.PlatformNotSupportedException: Message transmission mode is not supported on this platform."

According to the following link, it's not yet implemented on unix/linux based OS:

https://github.com/dotnet/corefx/issues/25161

Jean Jacques Uzabumuhire  Jul 18, 2019 
Printed Page 631
Code example for anonymous types

I ran the code example with mono (.NET Core 2.2 on macOS), and I got the following error :

"Unhandled Exception:
System.UnauthorizedAccessException: Access to the path is denied. ---> System.IO.IOException: Bad file descriptor"

and the following result on the server side :

"Server received: -1"

I tried to search for an answer on the internet but I couldn't find any, any clarification is welcome.




Jean Jacques Uzabumuhire  Jul 18, 2019 
Printed Page 641
4th paragraph

I am using .NET Core 2.2 on Visual Studio for Mac 2019, and when I run the code example above the 4th paragraph, the compressed file is always 102 bytes instead of 241 bytes. Has the compression algorithm been improved ?

Jean Jacques Uzabumuhire  Jul 19, 2019 
Printed Page 642
1st paragraph

I am using .NET Core 2.2 on Visual Studio for Mac 2019, and when I run the code example referenced in the 1st paragraph, the compressed file is always around 860 bytes instead of 1073 bytes. Has the compression algorithm been improved ?

Jean Jacques Uzabumuhire  Jul 20, 2019