Get object with minimum value using extension method min()

雨燕双飞 提交于 2019-12-17 20:51:51

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/6414052/get-object-with-minimum-value-using-extension-method-min

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!