My code is supposed to take a user input, use that to determine the size of a 2d array, then turn the items in the array into incrementing integers from 0 onwards eg 0, 1, 2, 3, 4. This is the code I used:
int userInput = int.Parse(Console.ReadLine());
int[,] GridArray = new int[userInput, userInput];
int k = 0;
for (int i = 0; i < GridArray.Length; i++)
{
if (i == GridArray.GetLength(0))
{
k++;
}
int gridNumber = i + (k * GridArray.GetLength(0));
Console.Write(gridNumber + " ");
}
But the output from an input of 4 is like this: 0 1 2 3 8 9 10 11 12 13 14 15 16 17 18 19 Both a fix for my code and a method for doing what I am attempting easier would be greatly appreciated.