How to use LINQ on a multidimensional array to 'unwind' the array?

Kees C. Bakker picture Kees C. Bakker · Dec 11, 2012 · Viewed 16.1k times · Source

Consider the following array:

int[,] numbers = new int[3, 2] { { 2, 1 }, { 3, 4 }, { 6, 5 } };

I would like to use LINQ to construct an IEnumerable with numbers 2, 1, 3, 4, 6, 5.

What would be the best way to do so?

Answer

Tim Schmelter picture Tim Schmelter · Dec 11, 2012

Perhaps simply:

var all = numbers.Cast<int>();

Demo