Out of Range Exception 2D Array for Int Type List

Why am I getting an exception to the range here?

The method accepts int[][] numbersas a parameter.

My code is:

 List<int> myList = new List<int>();
 for (int i = 0; i < numbers.GetUpperBound(0); i++)
     {
       for (int z = 0; z < numbers.GetUpperBound(1); z++)
           {
                myList.Add(intervals[i][z]);
           }
      }

I tried Google, but I do not have glue.

+4
source share
1 answer

As mentioned in the comments, this is a jagged array, so the code in the question doesn't work. The way I'm browsing the array now is as follows:

 List<int> myList = new List<int>();
 for (int i = 0; i < intervals.Length; i++)
        {
            for (int z = 0; z < intervals[i].Length; z++)
            {

                myList.Add(intervals[i][z]);

            }
        }       
+3
source

All Articles