Errata

C# 6.0 Cookbook

Errata for C# 6.0 Cookbook

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
1.13
last statement in the given code solution

The following line appears to be incorrect:

public void SetData(T val) => data = value;

I think the name of the argument to the method should match that in the expression e.g.

public void SetData(T val) => data = val;

otherwise there is a compiler error

David Gartner  May 17, 2020 
1.17
middle of first code snippet

The PrintPortfolio method of the StockPortfolio class indicates that the field "_stocks" has a method named "DisplayStocks" associated with it. The type specified for "_stocks" does not have such a method. Trying to invoke the method causes an error.

public void PrintPortfolio(string title)
{
Console.WriteLine(title);
_stocks.DisplayStocks();
}

David Gartner  May 19, 2020 
Printed Page 7
CompareTo(other: Square): int

Unnecessary if check. Since the last two items the if...else...if chain return the same value, and we end on an else, then we can get rid of the final else if. It doesn't matter if that final self if passes or fails, the method still returns a -1. So, just get rid of it and save a bit of computing power while you're at it.

Francisco  Apr 21, 2022 
Printed Page 8
+Compare(firstSquare: object, secondSquare: object): int

A reference type can be of type Square and have a null value. Saying that a parameter needs to be of type Square, when the problem is that it has a null value, will not help your fellow developers when they use your code. You should check the firstSquare and secondSqure objects for null values before you try to cast them into objects of type Square.

Francisco  Apr 21, 2022 
Printed Page 8
+Compare(x: Square, y: Square): int

There's no null check. If this were a private method, then you could get away from not having a null check because developers using this class wouldn't have a way to pass in a null value to it. But, it's a public method, so anyone can call this method and pass in a null value.

Francisco  Apr 21, 2022 
Printed Page 10
Test


Hi,
I have purchased the print edition.

This is a great book. This communication is not about an errata. I got the source code from github. Can you please let me know how to run it? I ran it after setting the CSahrpRecipes as the startup project. But I am getting this error: {"Could not find file 'c:\\Windows\\vmgcoinstall.log'.":"c:\\Windows\\vmgcoinstall.log"}

Thanks

Nadarajan Kuzhandaivelu  Apr 28, 2020