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 對應(yīng)的數(shù)據(jù),其他的都過濾掉。
?
2 回答

搖曳的薔薇
TA貢獻(xiàn)1793條經(jīng)驗 獲得超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));
}

守候你守候我
TA貢獻(xiàn)1802條經(jīng)驗 獲得超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();
- 2 回答
- 0 關(guān)注
- 512 瀏覽
添加回答
舉報
0/150
提交
取消