使用扩展方法分获取对象,最小值() [英] Get object with minimum value using extension method min()

查看:145
本文介绍了使用扩展方法分获取对象,最小值()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

list.Min()获取我的最小值为整数。我想有一定财产十,我怎么能做到这一点的最小值在列表中的对象?

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 - 或者我相信无扩展也有类似的 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.

这篇关于使用扩展方法分获取对象,最小值()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆