使用扩展方法 min() 获取具有最小值的对象 [英] Get object with minimum value using extension method min()
本文介绍了使用扩展方法 min() 获取具有最小值的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
list.Min() 以整数形式获取最小值.我想获取 List 中具有某个属性 X 最小值的对象.我该怎么做?
list.Min() gets me the min value as integer. I want to get the object in List which has the min value for a certain property X. How can I do that?
推荐答案
看看 MinBy
在 MoreLINQ 中 - 或者我相信 Reactive扩展在 System.Interactive
中有类似的东西:
Have a look at MinBy
in MoreLINQ - or I believe Reactive Extensions has something similar in System.Interactive
:
var cheapestProduct = products.MinBy(p => p.Price);
如果有多个项具有最低值,则返回序列中最早的一项.
If more than one item has the lowest value, the earliest one in the sequence will be returned.
这篇关于使用扩展方法 min() 获取具有最小值的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文