为了将多维数组与LINQ一起使用,您只需要将其转换为
IEnumerable<T>。这很简单,这是两个示例查询选项
int[,] array = { { 1, 2 }, { 3, 4 } };var query = from int item in array where item % 2 == 0 select item;var query2 = from item in array.Cast<int>() where item % 2 == 0 select item;每种语法都会将2D数组转换为
IEnumerable<T>(因为您
intitem在一个from子句中或
array.Cast<int>()在另一个子句中说了)。然后,您可以使用LINQ方法过滤,选择或执行所需的任何投影。



