[英]linq: Get Max value, then get an associated property of that result
I have a collection of objects that have properties of Date (DateTime) and Status (String). 我有一个具有日期(DateTime)和状态(String)属性的对象集合。
I need to get the value of Status that is associated with the most recent Date. 我需要获取与最新日期关联的状态值。
I can get the most recent date with this: 我可以得到最新的日期:
var MostRecentDate = ListOfObjects.Max(x => x.MyDate);
However, how can I get the value of Status that is associated with MostRecentDate? 但是,如何获取与MostRecentDate关联的Status的值?
Any ideas are very welcome. 任何想法都非常欢迎。 Thanks :o)
谢谢:o)
尝试使用OrderByDescending
var MostRecent = ListOfObjects.OrderBydescending(x => x.MyDate).First();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.