为了账号安全,请及时绑定邮箱和手机立即绑定

lambda 分组过滤

lambda 分组过滤

C#
UYOU 2018-12-07 09:15:03
List<Apple> listapple = new List<Apple>(); listapple.Add(new Apple() { dt = DateTime.Now.AddDays(1), geely_wsordercode = "SO01", pricetypecode = "SV100", sapValue = 100 }); listapple.Add(new Apple() { dt = DateTime.Now.AddDays(2), geely_wsordercode = "SO01", pricetypecode = "SV200", sapValue = 200 }); listapple.Add(new Apple() { dt = DateTime.Now.AddDays(3), geely_wsordercode = "SO01", pricetypecode = "SV200", sapValue = 300 }); listapple.Add(new Apple() { dt = DateTime.Now.AddDays(4), geely_wsordercode = "SO01", pricetypecode = "SV200", sapValue = 400 }); listapple.Add(new Apple() { dt = DateTime.Now.AddDays(5), geely_wsordercode = "SO02", pricetypecode = "SV100", sapValue = 500 }); listapple.Add(new Apple() { dt = DateTime.Now.AddDays(6), geely_wsordercode = "SO02", pricetypecode = "SV100", sapValue = 600 }); listapple.Add(new Apple() { dt = DateTime.Now.AddDays(7), geely_wsordercode = "SO02", pricetypecode = "SV100", sapValue = 700 }); 希望用 lambda ,通过 geely_wsordercode 和 pricetypecode 分组,取最大时间的 sapValue 对应的数据,其他的都过滤掉。  
查看完整描述

2 回答

?
摇曳的蔷薇

TA贡献1793条经验 获得超6个赞

var listresult= listapple.GroupBy(x => new {x.geely_wsordercode, x.pricetypecode}).ToList();

foreach (var variable in listresult)
{
var temp= variable.FirstOrDefault(x => x.dt == variable.Max(y => y.dt));
}

查看完整回答
反对 回复 2018-12-24
?
守候你守候我

TA贡献1802条经验 获得超10个赞

List<int> sapValue = listapple.Where(r => listapple.GroupBy(x => new { x.geely_wsordercode, x.pricetypecode }).Select(m => m.Max(n => n.dt)).ToList().Contains(r.dt)).Select(r => r.sapValue).ToList();

查看完整回答
反对 回复 2018-12-24
  • 2 回答
  • 0 关注
  • 489 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信