CodeJam
CodeJam copied to clipboard
EnumerableExtensions.MinBy and MaxBy throw when collection has only null values
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.
https://github.com/microsoft/referencesource/blob/5697c29004a34d80acdaf5742d7e699022c64ecd/System.Core/System/Linq/Enumerable.cs#L1540
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