Why this code compiles :
byte[][] my2DArray =new byte [][]{
new byte[] {1, 2},
new byte[] {3, 4},
};
var r = my2DArray.SelectMany(f=> f);
while this one isn't :
byte[,] my2DArray =new byte [2,2]{
{1, 2},
{3, 4},
};
var r = my2DArray.SelectMany(f=> f);
isn't [][]
is as [,]
?
edit
why do I need that ?
I need to create a single dimension array so it will be sent to GetArraySum
of course I can create overload , but I wanted to transform the mutli dim into one dim. (GetArraySum
serves also pure dimensional arrays).
void Main()
{
byte[][] my2DArray =new byte [][]{
new byte[] {1, 2},
new byte[] {3, 4},
};
var sum = GetArraySum(my2DArray.SelectMany(f=> f).ToArray());
}
int GetArraySum(byte [] ar)
{
return ar.Select(r=>(int)r).Sum();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…