我想在我的数组即Matrix类中根据用户输入在构造函数中添加新的维度。
例如:
例如:
var matrix = new Matrix<int>(3,2,4); // is 3 dimensional array
这是我的Matrix
类:
class Matrix<T>
{
private T[][] mArray;
private readonly int mCols;
private readonly int mRows;
public Matrix(params int[] args)
{
//here is what I ve tried.
/*
mCols = args[0];
mRows = args[1];
mArray = new T[mCols][];
for (int i = 0; i < mCols; i++)
mArray[i] = new T[mRows];
*/
// how to create a multidimensional array based on "args" length?
}
}
问题:如何根据“args”的长度创建多维数组?