Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用linq选择锯齿数组的列_C#_Linq - Fatal编程技术网

C# 如何使用linq选择锯齿数组的列

C# 如何使用linq选择锯齿数组的列,c#,linq,C#,Linq,如何在C中使用linq来选择整数交错数组的列,我选择行如下 int[][] values; .... var rows = from row in values select row; 谢谢您的帮助。再添加一行: var cols = values.SelectMany(v=>v.Select(c=>c)) int[][] values; .... var rows = from row in values select row; var cols = rows.SelectMa

如何在C中使用linq来选择整数交错数组的列,我选择行如下

int[][] values;
....
var rows = from row in values select row;
谢谢您的帮助。

再添加一行:

var cols = values.SelectMany(v=>v.Select(c=>c))
int[][] values;
....
var rows = from row in values select row;
var cols = rows.SelectMany(x => x);

您也可以这样做:

        int[][] values = new int[5][];
        values[0] = new int[5] { 1, 2, 3, 4, 5 };
        values[1] = new int[5] { 1, 2, 3, 4, 5 };
        values[2] = new int[5] { 1, 2, 3, 4, 5 };
        values[3] = new int[5] { 1, 2, 3, 4, 5 };
        values[4] = new int[5] { 1, 2, 3, 4, 5 };

        var rows = from r in values where r[0] == 1 select r[0];

        //two options here for navigating each row or navigating one row

        var rows = from r in values[0] where r == 1 select r;
一些注意事项:

这不会从不同大小的数组中保留空空间,记住-锯齿状。 rowindex ri未使用,可以删除。 如果需要,可以使用rowindex为emptyspace生成值
在我看来,这会使数组变平,有没有办法将列作为数组?在我看来,这会使数组变平,有没有办法将列作为数组?
IEnumerable<IEnumerable<int>> columns = values
  .SelectMany((row, ri) => row
    .Select((x, ci) => new {cell = x, ci, ri}))
  .GroupBy(z => z.ci)
  .Select(g => g.Select(z => z.cell));