【发布时间】:2018-11-14 22:32:22
【问题描述】:
所以我需要提取符合以下条件的记录:
PayDate 最低但 ReconciliationDate 最高的记录。 可以看到这样的记录示例
public class Data {
public string Name { get; set; }
public DateTime PayDate { get; set; }
public DateTime ReconciliationDate { get; set; }
}
--------------------------------------------------
| Name | PayDate | ReconciliationDate |
--------------------------------------------------
| Andrew | 11/14/2018 | 07/01/2018 |
--------------------------------------------------
| Andrew | 10/14/2018 | 06/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 08/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 03/01/2018 |
--------------------------------------------------
| Andrew | 05/14/2018 | 10/01/2018 |
所以要返回的正确记录是#5
如何使用 C# 实现这一点?
到目前为止我有这个:
var recordsNextCouponPaymentAfterLastOfMonth = externalInterestForSecurity.Where(aExternalRecord => aExternalRecord.PayDate > priorMonthEnd);
【问题讨论】:
-
您可以使用
OrderBy、OrderByDescending、ThenBy和/或ThenByDescending对列表进行排序,然后取第一行。见this question。