【发布时间】:2015-04-10 10:28:37
【问题描述】:
我有 2 个不同类型的列表,我想按日期分组,然后合并每个日期的 2 个列表。
我的 2 列表看起来像这样。
List<Payment> payments = new List<Payment>
{
new Payment{Date = '2014-01-01 12:23:52', PaymentSum = 300},
new Payment{Date = '2014-01-01 12:23:53', PaymentSum = 100},
new Payment{Date = '2014-01-02 12:23:52', PaymentSum = 300},
}
List<Invoice> invoices = new List<Invoice>
{
new Invoice{Date = '2014-01-01 12:20:32', InvoiceSum= 300},
new Invoice{Date = '2014-01-01 12:21:53', InvoiceSum= 200},
new Invoice{Date = '2014-01-02 12:24:52', InvoiceSum= 300},
}
我希望结果看起来像这样:
List<NewItem> newItems= new List<NewItem>
{
new NewItem{Date = '2014-01-01', InvoiceSum= 500, PaymentSum = 400},
new NewItem{Date = '2014-01-02', InvoiceSum= 300, PaymentSum = 300},
}
提前致谢!
【问题讨论】:
-
你有没有尝试过?