Array operations with n-dimensional array using LINQ (C#)

后端 未结 6 1401
温柔的废话
温柔的废话 2021-02-06 03:23

Assume we have a jagged array

int[][] a = { new[] { 1, 2, 3, 4 }, new[] { 5, 6, 7, 8 }, new[] { 9, 10, 11, 12 } };

To get a sum of second row a

6条回答
  •  面向向阳花
    2021-02-06 03:54

    A simpler way is doing like below

     var t = new List>();
     int[][] a = t.Select(x => new int[]{ x.Item1, x.Item2}).ToArray(); 
    

提交回复
热议问题