It's not the first time I'm getting this error on snippets I found on forums and I cannot understand why. Also I'm yet a C#
noob.
Whenever I try something like arr.Max(x => x.Length)
I'm getting a NPE on x
in x.Length
. Something must be wrong with the param variable I'm passing, because I only get this error on execution.
private string[,] jaggedTo2D(string[][] arr)
{
string[,] arr2 = new string[arr.Length, arr.Max(x => x.Length)];
for (var i = 0; i < arr.Length; i++)
{
for (var j = 0; j < arr[i].Length; j++)
{
arr2[i, j] = arr[i][j];
}
}
return arr2;
}