-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
MaxBy inconsistent results with tie-breaks #61317
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/area-system-linq Issue DetailsDescriptionWhen all the items in the list have a null key MaxBy returns the last item in the list. When they all have a key value but the values are the same the first item is returned. To me that seems inconsistent. Reproduction Steps
Expected behaviorThe Reproduction code should print AA or BB. Actual behaviorThe reproduction code prints AB Regression?I think this is new in .Net 6. Known WorkaroundsDon't use lists with all the keys the same. ConfigurationI got this in .Net 6 RC2. I don't think the OS or CPU are going to make any difference. Other informationNo response
|
Hi @martingbrown, this is by-design behavior intended to preserve compatibility with null element handling in the existing That being said, whether the As a workaround -assuming order of selection is important- I would recommend avoiding var r2 = l2.MaxBy(t => t.Item1 ?? ""); |
Description
When all the items in the list have a null key MaxBy returns the last item in the list. When they all have a key value but the values are the same the first item is returned. To me that seems inconsistent.
Reproduction Steps
Expected behavior
The Reproduction code should print AA or BB.
Actual behavior
The reproduction code prints AB
Regression?
I think this is new in .Net 6.
Known Workarounds
Don't use lists with all the keys the same.
Configuration
I got this in .Net 6 RC2. I don't think the OS or CPU are going to make any difference.
Other information
No response
The text was updated successfully, but these errors were encountered: