Home
Options

Array Indexes

Consider the following jagged array declaration:

    int[][][] three = new int[][][] { new int[][] { new int[] { 1, 2, 3}, new int[] { 4, 5}},
            new int[][] {new int[] {8, 9, 2, 1}, new int[] {0, 9, 2}, new int[] { 1, 2}}};

If I use the Dump method against this array, I get the outcome below, where the type listed is Int32[][][2]. Printing the type of the variable using three.GetType().Dump() gives System.Int32[][][] so I assume - though I might be wrong - that the dimensions being reported are part of LINQPad's own output, not necessarily C#'s.

My question is why is the 2 value in Int32[][][2] the last one? Shouldn't it be the first instead, as accessing for example the first element of type int[][] from the two that exist inside the variable requires using three[0][...][...]. The same goes for the "inner" elements as well - shouldn't their lengths be inverted (e.g. Int32[3][] instead of Int32[][3])?

I'm seeing this with LINQPad 7, but iirc it was the same in previous versions as well.

Comments

Sign In or Register to comment.