Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

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

Open
Labels
Pri3Indicates issues/PRs that are low priorityarea-System.Linq
Milestone
@binki

Description

@binki

In regards tonull, the documentation states this:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri3Indicates 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


      [8]ページ先頭

      ©2009-2025 Movatter.jp