I am trying to assign values to a 2D array using 2 for
loops. Here is my code:
void Test()
{
int[,] grid = { { 0 } };
for (int x = 0; x <= 7; x++)
{
for (int y = 0; y <= 7; y++)
{
grid[x, y] = x * y;
}
}
}
However, I get a System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'
after the for
loops. What is causing this and how can I fix it?