Rotate - Transposing a List> using LINQ C#

前端 未结 6 1086
半阙折子戏
半阙折子戏 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 12:14

    Try this:

    List> PersonInfo = new List>(){
    new List() {"John", "Peter", "Watson"},
    new List() {"1000", "1001", "1002"}};
    
    List> PivitedPersonInfo = new List>();
    for (int i = 0; i < PersonInfo.First().Count; i++)
    {
        PivitedPersonInfo.Add(PersonInfo.Select(x => x.ElementAt(i)).ToList());
    }
    

提交回复
热议问题