In order to use your multidimensional array with LINQ, you simply need to convert it to IEnumerable<T>
. It’s simple enough, here are two example options for querying
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;
Each syntax will convert the 2D array into an IEnumerable<T>
(because you say int item
in one from clause or array.Cast<int>()
in the other). You can then filter, select, or perform whatever projection you wish using LINQ methods.