这是二维数组:
int[][] array2D = new int[7][];
for (int i = 0; i < 7; i++)
array2D[i] = new int[7];
如何将以下内容转换为 LINQ 查询,或使用可枚举的方法来实现相同的输出?
var lst = new List<Point>();
for (int r = 0; r < array2D.Length; r++)
for (int c = 0; c < array2D[r].Length; c++)
if (array2D[r][c] == 0)
lst.Add(new Point(c, r));
编辑 - 基于@'King King's answer的解决方案
var lst = m_boardArr.SelectMany((row, rowIndex) =>
row.Select((val, colIndex) =>
new { val, point = new Point(colIndex, rowIndex) })
.Where(col => col.val == 0)
.Select(col => col.point)).ToList();