Im trying to find out a way to convert a 2d array of one type to another in a single line of code.
This is a personal learning experience rather than a need to do it in one line!!
Ive gotten so far as to convert it into IEnumerable<Tuple<ushort,ushort>>
. Not sure where to go from here.
int[,] X = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 } };
var Result = (from e in X.OfType<int>() select e)
.Select(S => (ushort)S)
.Select((value, index) => new { Index = index, Value = value })
.GroupBy(x => x.Index / 2)
.Select(g => new ushort[,] { { g.ElementAt(0).Value,
g.ElementAt(1).Value } });
Need to somehow convert the collection of Tuples into a ushort[,]
EDIT:
Just clarifying the question.
How do I convert a int 2d array into a ushort 2d array using a single line of code in linq?
EDIT:
Ive updated my code.
I now have it resulting in a IEnumerable collection of ushort[,].
I need to now find a way to concatonate all these into a single ushort[,]