我想获取可枚举中属性为最大值的所有元素:
IEnumerable<Person> allOldest = people.GroupBy(p => p.Age)
.OrderByDescending(i=>i.Key).First().Select(_=>_);
Run Code Online (Sandbox Code Playgroud)
.NET 6 引入了MaxBy返回最大项的功能:
Person uniqueOldest = people.MaxBy(person => person.Age);
Run Code Online (Sandbox Code Playgroud)
MaxBy不能帮助我吗?还有比第一个示例更优雅的解决方案吗?