You can get clever by writing a method using the params keyword which will automatically create an array of arrays for you.
To do that, you have to write an intermediary wrapper class for the arrays, because the params keyword can only be used with a single dimensional array.
I really only provide this code for the curious - you probably wouldn't really need to go to these lengths in real code. However, if you did find yourself often wanting to iterate over a set of two dimensional arrays, you can use this approach.
After writing the (reusable) helper classes your code to iterate the arrays would look like this:
string[,] op1 = new string[9, 9];
string[,] op2 = new string[9, 9];
string[,] op3 = new string[9, 9];
IterateArrays<string>(processArray, op1, op2, op3);
Where the processArray() method would be along these lines:
static void processArray(string[,] array, int index)
{
Console.WriteLine("Processing array with index " + index);
}
Here's the full compilable example:
using System;
namespace ConsoleApp1
{
public class ArrayWrapper<T>
{
public T[,] Array;
public static implicit operator ArrayWrapper<T>(T[,] array)
{
return new ArrayWrapper<T> {Array = array};
}
}
sealed class Program
{
void run()
{
string[,] op1 = new string[9, 9];
string[,] op2 = new string[9, 9];
string[,] op3 = new string[9, 9];
IterateArrays<string>(processArray, op1, op2, op3);
}
static void processArray(string[,] array, int index)
{
Console.WriteLine("Processing array with index " + index);
}
public static void IterateArrays<T>(Action<T[,], int> action, params ArrayWrapper<T>[] arrays)
{
for (int i = 0; i < arrays.Length; ++i)
action(arrays[i].Array, i);
}
static void Main(string[] args)
{
new Program().run();
}
}
}
Like I said, this is just to show how you can approach it. It'd just use @thumbmunkeys suggestion in real code.