dotnet / dotnet-api-docs

.NET API reference documentation (.NET 5+, .NET Core, .NET Framework)
https://docs.microsoft.com/dotnet/api/
Other
725 stars 1.56k forks source link

Software Developer #10421

Closed cosminjeler closed 1 month ago

cosminjeler commented 1 month ago

Type of issue

Code doesn't work

Description

The documentation of Max(IEnumerable<Nullable<Int32>>) states in the Remarks section that: If the source sequence is empty or contains only values that are null, this function returns null.

However Array.Empty<int>().Sum() returns 0 (zero)... (not null as stated)

Page URL

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

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

dotnet-policy-service[bot] commented 1 month ago

Tagging subscribers to this area: @dotnet/area-system-linq

eiriktsarpalis commented 1 month ago

The code sample you are sharing will end up using the Enumerable.Max(IEnumerable<int>) overload)) and not the nullable variant. You can force the expected overload as follows:

Array.Empty<int?>().Sum()