在C#编程语言中,如何传递多维数组的一行?例如,假设我有以下内容:
int[,] foo;
foo = new int[6,4];
int[] least;
least = new int[6];
for(int i = 0; i < 6; i++)
{
least[i] = FindLeast(ref foo[i]); //How do I pass the ith row of foo???
}
还有,谁能向我解释在 C# 中使用矩形和锯齿状数组的好处?这是否发生在其他流行的编程语言中? ( java ?) 感谢您的帮助!
最佳答案
你不能传递一行矩形数组,你必须使用锯齿状数组(数组的数组):
int[][] foo = new int[6][];
for(int i = 0; i < 6; i++)
foo[i] = new int[4];
int[] least = new int[6];
for(int i = 0; i < 6; i++)
least[i] = FindLeast(foo[i]);
编辑
如果您发现使用锯齿状数组很烦人并且迫切需要一个矩形数组,一个简单的技巧可以拯救您:
int FindLeast(int[,] rectangularArray, int row)
关于C#多维数组的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9590144/