C#行的多维数组

Cod*_*lus 8 c# arrays row multidimensional-array indices

在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???
}
Run Code Online (Sandbox Code Playgroud)

另外,有人可以向我解释在C#中使用矩形和锯齿状阵列的好处吗?这是否会出现在其他流行的编程语言中?(Java?)感谢您的帮助!

Bla*_*ear 8

你不能传递一行矩形数组,你必须使用锯齿状数组(数组数组):

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]);
Run Code Online (Sandbox Code Playgroud)

编辑
如果您发现使用锯齿状阵列非常烦人并且迫切需要一个矩形阵列,一个简单的技巧将为您节省:

int FindLeast(int[,] rectangularArray, int row)
Run Code Online (Sandbox Code Playgroud)