到列表轉換爲數組[,]有代碼:轉換列表contaning列表<double>單挑扁平化陣列
double[,] arr = new double[list.Count, list[0].Length];
for (int i = 0; i < list.Count; i++)
{
for (int j = 0; j < list[0].Length; j++)
{
arr[i, j] = list[i][j];
}
}
我想將它轉化成扁平陣列所以使用的事實
Flattened array index computation
array[(Y coordinate * width) + X coordinate]
2D array index computation
array[Y coordinate, X coordinate]
代碼更改
double[] arr = new double[list.Count * list[0].Length];
for (int i = 0; i < list.Count ; i++)
{
for (int j = 0; j < list[0].Length; j++)
{
arr[i] = list[i * list[0].Length + j];
}
}
但什麼是代碼爲List < List <double> >
轉換FL數組陣列? 作爲上述代碼,可以在2個循環中完成嗎?
的List<List<double>>
表示double[,] arr
不應'ARR [I] =列表[I *列表[0]。長度+ D];'是'arr [i * list [0] .Length + j] = list [i] [j];'? – CompuChip
如果要將列表的列表轉換爲多維數組,那不是「扁平化」。展平列表將導致一維數組。 – dcastro