我有一个关于C#中多维数组的基本问题。
目前我有以下数组:
float[] matrix = new float[16];
我需要创建一个二维数组,每行包含先前提到的16个浮点数。此外,二维数组中的行数在程序开始时是未知的(即它将基于一个变量)。
如何使用高效的数据结构创建这样的数组?
// init the array
float[,] matrix = new float[4,4];
// loop through the array
for(int col = 0; col < matrix.GetLength(0); col++)
for(int row = 0; row < matrix.GetLength(1); row++)
Console.WriteLine(matrix[col, row]);
const Int32 arraySize = 16;
var list = new List<float[]>();
var array = new float[arraySize];
// do stuff to the array
list.Add(array);
float[,] arr2D = new float[12,12];
float[][] floats = new float[12][];
for(int i=0; i< 12; i++)
{
floats[i] = new float[12];
}