0

我有一个 list1 的列表

CurrentYearDate    Marks1   LastYearDate    Marks2         
09/01/2012         200       
09/02/2012         10        
09/03/2012         30
09/04/2012         40       

我有一个 list2 的列表

CurrentYearDate    Marks1   LastYearDate    Marks2         
                            9/01/2011         10
                            09/02/2011        10
                            09/03/2011        30
                            09/04/2011        40

我需要将两个列表合并在一起列表主我有一个列表与 list1

CurrentYearDate    Marks1   LastYearDate    Marks2         
09/01/2012         200      9/01/2011         10
09/02/2012         10       09/02/2011        10
09/03/2012         30       09/03/2011        30
09/04/2012         40       09/04/2011        40
4

1 回答 1

0

如果索引排成一行,如您的示例所示,以便每个列表中的第一项相互对应,那么您可以使用Zip

var mergedLists = list1.Zip(list2, (a,b)=> new YourClassName()
    {
        CurrentYearDate = a.CurrentYearDate,
        Marks1 = a.Marks1,
        LastYearDate = b.LastYearDate,
        Marks2 = b.Mark2,
    });

如果索引不对应,那么您需要使用Join

var joinedLists = list1.Join(list2, curr => curr.CurrentYearDate, last => last.LastYearDate.AddYears(1), (a,b)=> new YourClassName()
    {
        CurrentYearDate = a.CurrentYearDate,
        Marks1 = a.Marks1,
        LastYearDate = b.LastYearDate,
        Marks2 = b.Mark2,
    });
于 2013-04-15T19:41:44.917 回答