-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chap 06: Comparing objects #93
Comments
It's nothing to do with Visual Studio Code. It is a mistake in the printed book. The Person class has a Name property defined as a nullable string but that statement does not check for null. That's why the errata exists to fix that, as well as improve null handling in other ways too. |
Well, it's not IN the errata, so I thought that I'd bring it to your attention. If you are planning on adding it, then great. |
Sorry! It was not my intention to be rude. The errata as it exists both fixes the issue and improves the code example, so there is nothing to add. That's all I meant. |
Well, as a user, I went to your errata page specifically to find out why that page does not work and I find absolutely NO reference to the fact that there is an error in the book. I almost pitched the book (means to throw it in the garbage) because the book is apparently wrong but there is no reference to the error. |
Page 235:
the line "int result = x.Name.Length.CompareTo(y.Name.Length) results in the errors "'Name may be null here. Dereference of a possibly null reference".
To fix it, you must test to make sure that Name is not null first:
if((x is not null) && (y is not null))
{
if(x.Name is null) return 1;
if(y.Name is null) return -1;
int result = x.Name.Length.CompareTo(y.Name.Length);
}
Obviously, the errors disappear if you modify the file according to the "errata" for null values for page 235, but, as printed, the text does not work.
A possible VS Code version issue? Using VS Code version 1.69.1
The text was updated successfully, but these errors were encountered: