0

I am wanting to create a 2d array to produce a grid of int values the size of the grid needs to be 100 * 100

Example Grid

1   2   3  .........100

101 102 103.........200

201 202 303.........300

I produced ths

    int rows = 100;
    int columns = 100;

    public int[,] InitIntArray() {
        int[,] grid = new int[rows,columns];
        int number = 1;

        for (int i = 0; i != rows; i++)
        {

            for (int j = 0; j != columns; j++)
                grid[i, j] = number;
                number++;
        }

        return grid;
    }

When I use my code everything seems to work fine until I try to access the columns. all I get when I use grid.getValue() is 1.

2 Answers 2

2

Missed one curvy

    for (int i = 0; i != rows; i++)
    {

        for (int j = 0; j != columns; j++)
        {
            grid[i, j] = number;
            number++;
        }
    }
Sign up to request clarification or add additional context in comments.

1 Comment

LOL thanks, I knew it would be something simple sometimes just need some fresh eyes on it. Thanks
0
    for (int i = 0; i < rows; i++)

And the other for-loop

    for (int j = 0; j < columns; j++)
    {
        grid[i, j] = number;
        number ++;
    }

You might want to read on how for-loops work, http://www.thegeekstuff.com/2012/12/c-loops-examples/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.