在c#中迭代数组

iJa*_*ade 0 c# arrays

考虑我有许多数组如下:

string[,] op1 = new string[9, 9];
string[,] op2 = new string[9, 9];
string[,] op3 = new string[9, 9];
Run Code Online (Sandbox Code Playgroud)

如何迭代这样的数组,如;

int i;
int j;
for(i=0; i<3; i++) {
    // Iterate all the above three arrays here
}
Run Code Online (Sandbox Code Playgroud)

我想op通过改变索引来动态迭代所有数组.我正在使用C#

thu*_*eys 9

你可以动态制作一个数组并迭代:

string[,] op1 = new string[9, 9];
string[,] op2 = new string[9, 9];
string[,] op3 = new string[9, 9];

foreach (var item in new[] { op1, op2, op3 })
{
     //...
}
Run Code Online (Sandbox Code Playgroud)