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.