我正在尝试从列表中获取最大值,但如果有多个最大值,则要获取所有最大值。
例如,我有: Name1,31 Name2,35 Name3,33 Name4,35
我想要得到: {Name2,35}和{Name4,35}
我尝试使用MaxBy();
但那只返回第一个项目(Name2,35) 非常感谢您的帮助
struct Amounts
{
public string Name;
public int Total;
}
Amount highestAmount = amounts.MaxBy(x => x.Total);
Amount highestAmount = amounts.MaxBy(x => x.Total);
amounts.GroupBy(x => x.Total).MaxBy(g => g.Key)
- Alexander Petrov