Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Enumerable.Min<TSource>() and Enumerable.Max<TSource>() wording regarding null for reference types is misleading #7922

Copy link
Copy link
Open
@binki

Description

@binki
Issue body actions

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 are null, this method returns null.

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri3Indicates issues/PRs that are low priorityIndicates issues/PRs that are low priorityarea-System.Linq

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.