Take .NET arrays that illustrate this well:
C # has a distinction between gear arrays that are defined in a nested manner:
int[][] jagged = new int[3][];
Each nested array can have a different length:
jagged[0] = new int[3]; jagged[1] = new int[4];
(And note that one of the nested arrays is not initialized at all, i.e. null
.)
In contrast, a multidimensional array is defined as follows:
int[,] multidim = new int[3, 4];
There is no point in talking about nested arrays, and indeed, an attempt to access multidim[0]
will be a compile-time error - you need to access it by providing all sizes, i.e. multidim[0, 1]
.
Their types are also different, as the above ads show.
In addition, their processing is completely different. For example, you can iterate over the above array with binding to an object of type int[]
:
foreach (int[] x in jagged) …
but iterating over a multidimensional array is performed with elements of type int
:
foreach (int x in multidim) …
Conceptually , an array with teeth is an array of arrays (... arrays of arrays ... ad infinitum) T
, and a multidimensional array is an array T
with a set of access patterns (i.e., the index is a tuple).