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
That's a fair point - LINQPad should invert the indexers in the type description to match what C# does. This would also ensure that arrays such as
int[][4,5]
show with a correct heading:https://ericlippert.com/2009/08/17/arrays-of-arrays/
There should be a fix for this in 8.4.3. LINQPad now shows C#-style indexers in type descriptions rather than Reflection-style indexers.
Just checked with 8.4.10 and it looks good (below). Thank you also for the valuable info I just learned (Eric's article +
Dump
overload with a string parameter which I didn't know about).