CodeJam icon indicating copy to clipboard operation
CodeJam copied to clipboard

EnumerableExtensions.MinBy and MaxBy throw when collection has only null values

Open NN--- opened this issue 3 years ago • 2 comments

string?[] a = { null, null };
var m = a.MinBy(x => x); // throws no InvalidOperationException collection has no elements.

This happens since the methods looks for non default value while the correct is to have an indicator for not empty enumeration.

NN--- avatar Jun 12 '21 22:06 NN---

https://github.com/microsoft/referencesource/blob/5697c29004a34d80acdaf5742d7e699022c64ecd/System.Core/System/Linq/Enumerable.cs#L1540

NN--- avatar Jun 12 '21 22:06 NN---

https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.minby?view=net-6.0 https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.maxby?view=net-6.0

NN--- avatar Aug 31 '21 08:08 NN---