Open binki opened 2 years ago
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.
I guess this does not apply to .Max()
unless you use the overload which allows passing in a custom IComparer<T>
implementation or you have implemented the IComparable<T>
interface. The IComparable<T>
interface documentation states:
By definition, any object compares greater than
null
, and two null references compare equal to each other.
So in .Max()
the filtering would normally have no effect on the result.
Tagging subscribers to this area: @dotnet/area-system-linq See info in area-owners.md if you want to be subscribed.
Author: | binki |
---|---|
Assignees: | - |
Labels: | `Pri3`, `area-System.Linq`, `:watch: Not Triaged` |
Milestone: | - |
Thanks for reporting! @binki if you're interested in contributing a fix there is an Edit button (pen icon) on https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.min?view=net-6.0 which will point you to the right file to edit
Also if this was already fixed here: https://github.com/dotnet/dotnet-api-docs/pull/7927 please close the issue
In regards to
null
, the documentation states this:It also states:
This leads me to believe that the minimum value will be calculated purely based on the output of
IComparable<T>.Compare(T, T)
. That is, the output of.Min()
would be the same as.OrderBy(x => x).First()
and the output of.Max()
would be the same as.OrderBy(x => x).Last()
. Or that ifComparer<T>.Default.Compare(a, b) < 0
, then the output ofnew[] { a, b, }.Min()
would bea
. However, I found the following behavior instead:with output:
By experiencing this and examining the source, I know that
.Min()
and.Max()
implicitly filter out any values equal tonull
as the first step (including nullable value types which box tonull
). However, this is not obvious from the documentation.May you please alter the documentation to document this behavior?
Thanks!