c# - C# - 返回 PayDate 最低但 ReconciliationDate 最高的记录
问题描述
所以我需要提取符合以下条件的记录:
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);
解决方案
您正在寻找 LINQ 方法OrderBy
和ThenBy
在你的情况下
.OrderBy(x => x.PayDate).ThenByDescending(x => x.ReconciliationDate).First
推荐阅读
- flutter - 为什么我不能使用条件更改页面但凸起的按钮有效?
- maven - SonarQube 插件,用于修改现有代码覆盖率的评估
- java - 类未从 Spring Boot 中的 Get API 请求映射,如何映射到对象>
- dart - 直接将 List 传递给方法失败,但将其包装到变量中有效
- c# - C#如何让不同速度的进程一起工作
- javascript - 回调函数有问题
- python - Python:无名关键字参数列表
- android - Android 单元测试改造失败
- java - 使用 mySQL 从 Spring Boot 开始时,Javers 给出重复的键名“jv_global_id_owner_id_fk_idx”
- kql - 如何在日期之间创建 kql 查询