Rotate - Transposing a List> using LINQ C#

前端 未结 6 1085
半阙折子戏
半阙折子戏 2020-11-29 11:12

I\'m having a List>, which is return from the remote data source (i.e., WCF). So, I need to modify the following data into a user-frien

6条回答
  •  生来不讨喜
    2020-11-29 11:58

    Assuming there are only ever 2 lists inside PersonInfo:

    var rotated = PersonInfo[0]
        .Zip(PersonInfo[1], (a, b) => new List { a, b }).ToList();
    

    If there can be any number of Lists inside of PersonInfo:

    Enumerable.Range(0, PersonInfo[0].Count)
        .Select(i => PersonInfo.Select(lst => lst[i]).ToList()).ToList();
    

提交回复
热议问题