我需要创建二维锯齿状数组。想想一个矩阵。行数已知,列数未知。例如,我需要创建 10 个元素的数组,其中每个元素的类型为 string[]。为什么我需要那个?列数未知 - 此函数必须简单地进行分配并将数组传递给其他函数。
string[][] CreateMatrix(int numRows)
{
// this function must create string[][] where numRows is the first dimension.
}
更新
我有 C++ 背景。在 C++ 中,我会编写以下内容(不要介意语法)
double ** CreateArray()
{
double **pArray = new *double[10]() // create 10 rows first
}
更新 2
我正在考虑使用 List,但我需要对行和列都进行索引访问。
最佳答案
返回新字符串[numRows][];
关于c# - 我需要在 C# 中创建二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3881684/