Skip to content

Enumerable.max method does not return null if source sequence is empty #10739

@racnicolau

Description

@racnicolau

Type of issue

Other (describe below)

Description

The documentation for Enumerable.max [Max(IEnumerable)] states the following:
"If TSource is a reference type and the source sequence is empty or contains only values that are null, this method returns null."
This is not true as with an empty source sequence I am get the following exception:
"System.InvalidOperationException: Sequence contains no elements"

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.max?view=net-8.0#system-linq-enumerable-max-2(system-collections-generic-ienumerable((-0))-system-func((-0-1)))

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Linq/Enumerable.xml

Document Version Independent Id

422bf5c0-9b03-1bed-adbf-d4c3b375815d

Article author

@dotnet-bot

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions