markjprice / cs12dotnet8

Repository for the Packt Publishing book titled "C# 12 and .NET 8 - Modern Cross-Platform Development Fundamentals" by Mark J. Price
564 stars 164 forks source link

Pages 316 and 317 - Sorting #52

Open rmantel23 opened 2 months ago

rmantel23 commented 2 months ago

1.

You already have an entry for this in the errata, but I don't think that is correct. The branch you marked as not being able to be reached can be reached if there are multiple null names, see example below:

image

image

2.

I think the below branch can never be reached though:

image

The above can be replaced by:

image

markjprice commented 2 months ago

I've moved the big comment and added a couple of new comments to clarify the code. The final else still needs to return 0 though to indicate that when both objects are null, they are equal.

rmantel23 commented 2 months ago

That final else will never be reached though the way you have it set up. If other is not null it goes into the first if. Then you have an 'else if (other is null)', but we already know it is null since it didn't go into the 1st if, and it will always go into the 2nd and never reach the final else. So, you can just make the 2nd an else instead and set position to -1 there.