S
S
sulim0003332019-01-20 22:49:52
C++ / C#
sulim000333, 2019-01-20 22:49:52

Multidimensional array, why didn't the piece of code work?

int[,] array2 = new int[10,10];

      array2 [10,9] = 1299;
      Console.WriteLine (array2[10,9]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
luna3956, 2019-01-20
@sulim000333

Because int[,] array2 = new int[10,10]; is an array with cells from array2[0,0] to array2[9,9]
Numbering starts from 0. That is, the first cell of a 10 by 10 array will be array2[0,0], and the last cell will be array2[9,9].
And you are trying to refer to a non-existent cell ([10,9]), so you get an error that you have out of range of the array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question