Open
Description
In regards to null
, 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[] { new int?(), }.Min() == new int?()}");
Console.WriteLine($"new int?[]{{ }}.Min() == new int?(): {new[] { new int?(), }.Min() == new int?()}");
has output:
new[]{ new int?(), }.Min() == new int?(): True
new int?[]{ }.Min() == new int?(): True
int?
(Nullable<int>
) is a value type, not a reference type. It is true that (object)new int?() == null
is true
, so it triggers the behavior of .Min()
which returns default(TSource)
and the 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).