【发布时间】:2020-07-16 12:50:17
【问题描述】:
如何在查询列表中减去数字?
var q = lists.Select(v => new LegalSuitReport
{
CargoQtystr= v.Claim.ClaimBLs.Select(qq => qq.JobBL.CargoQty).ToList(),
RecipetedQtystr = v.Claim.ClaimBLs.Select(qq => qq.JobBL.LandedQty).ToList()
diff= v.Claim.ClaimBLs.Select(qq => qq.JobBL.CargoQtystr) - v.Claim.ClaimBLs.Select(qq => qq.JobBL.LandedQty)
}).ToList().Select(qs => new LegalSuitReport()
{
CargoQty= string.Join(",", qs.CargoQtystr),
RecipetedQty = string.Join(",", qs.RecipetedQtystr)
diff = string.Join(",", qs.RecipetedQtystr)
}).ToList();
我想在这些cargoqty 和receiptedqty 中减去具有相同索引的数字,并且差异之间存在差异
List<decimal> cargoqty= new List<decimal>{500,100000,150};
List<decimal> RecipetedQtystr = new List<decimal>{5,90000,15};
List<decimal> diff= new List<decimal>{495,10000,135};
【问题讨论】:
-
你能分享一下,示例输入和例外输出。
-
中间不用
ToList() -
您的代码没有显示任何“减法”尝试。从样本来看,
Zip()会有所帮助 -
中间不需要使用ToList() =>请详细说明?
标签: c# asp.net-mvc linq