Convert 2 dimensional array

Manoj picture Manoj · Mar 13, 2009 · Viewed 24.2k times · Source

What is selectMany.ToArray() method? Is it a built in method in C#?

I need to convert two dimensional array to one dimensional array.

Answer

Marc Gravell picture Marc Gravell · Mar 13, 2009

If you mean a jagged array (T[][]), SelectMany is your friend. If, however, you mean a rectangular array (T[,]), then you can just enumerate the date data via foreach - or:

int[,] from = new int[,] {{1,2},{3,4},{5,6}};
int[] to = from.Cast<int>().ToArray();