You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From @Smoovsky on Thursday, December 2, 2021 5:39:28 AM
Describe the bug
I noticed new Sytem.Linq.Enumrable.MaxBy method provided in .NET 6.0: doc
The documentation states two types of exception ArgumentException and ArgumentNullException to be expected.
But InvalidOperationException may also be thrown for empty primitive type enumerables, see the example below.
To Reproduce
Steps to reproduce the behavior:
Snippet:
void Main()
{
var test1 = new Test[] { }.MaxBy(x => x.MyProperty); // no problem
var test2 = new Test[] { new Test { MyProperty = 1 }, new Test { MyProperty = 1 } }.MaxBy(x => x.MyProperty); // no problem
var test3 = new int[] { }.MaxBy(x => x); // exception here
}
public class Test
{
public int MyProperty { get; set; }
}