- Notifications
You must be signed in to change notification settings - Fork1.6k
Open
Description
In regards tonull
, the documentation states this:
If
TSource
is a reference type and the source sequence is empty or contains only values that arenull
, this method returnsnull
.
However, I found the following behavior:
Console.WriteLine($"new[]{{ new int?(), }}.Min() == new int?():{new[]{newint?(),}.Min()==newint?()}");Console.WriteLine($"new int?[]{{ }}.Min() == new int?():{new[]{newint?(),}.Min()==newint?()}");
has output:
new[]{ new int?(), }.Min() == new int?(): Truenew int?[]{ }.Min() == new int?(): True
int?
(Nullable<int>
) is a value type, not a reference type. It is true that(object)new int?() == null
istrue
, so it triggersthe behavior of.Min()
which returnsdefault(TSource)
andthe same behavior in .Max()` instead of throwing. However, from reading the documentation, I would expect the throw-on-empty behavior.
Please clarify the documentation (which seems to also omit any mention of the throw-on-empty behavior for non-reference types).