Answer the question
In order to leave comments, you need to log in
Why does an error occur when accessing an element of a 2-dimensional array?
Hello everyone!
I don't understand why, when accessing an array element, the compiler throws an error
System.IndexOutOfRangeException: "Index was outside the bounds of the array."
int[,] mass = new int[1,2];
mass[1,2] = 14; - здесь вылетает ошибка
Answer the question
In order to leave comments, you need to log in
Arrays are counted from zero, and you are trying to write something to the 3rd cell, although from 2
It's clear. It seemed to me that when you initialize an array and prescribe how many elements it should have, there is also a countdown from zero. It turned out not.
Thanks to all.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question