LINQ swap columns into rows

前端 未结 5 1904
死守一世寂寞
死守一世寂寞 2020-12-06 10:44

Is there a fancy LINQ expression that could allow me to do the following in a much more simpler fashion. I have a List>, assuming the L

5条回答
  •  [愿得一人]
    2020-12-06 11:25

    var inverted = Enumerable.Range(0, columnCount)
                   .Select(index => columnList.Select(list => list[index]));
    

    In short, we enumerate the column index from a range and use it to collect the nth element of each list.

    Please note that you'll need to check that every list has the same number of columns.

提交回复
热议问题