D
D
dev4002016-10-20 12:25:53
Arrays
dev400, 2016-10-20 12:25:53

What is the difference between a two-dimensional array and an array of arrays?

In fact, a two-dimensional array is an array with an array. What is the difference?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tikks, 2016-10-20
@dev400

The fundamental difference is that arrays within an array can have different dimensions.
If you visually imagine an array of arrays as a table, and internal ones as strings, then these strings can be of different lengths, this table will be like a stepped table. For a two-dimensional array, the table will be rectangular, all rows of the same length.
Pay attention to the Length property:
For an array of arrays myArray:
myArray.Lenth - will return the number of nested arrays,
myArray[0].Length - the size of the first nested array,
myArray[1].Length - the size of the second nested array, which in general is not equal to myArray[0].Length,
etc.
For multidimensional array myArray:
myArray.Lenth - the total will return the number of elements over all dimensions,
myArray.Rank - the number of array dimensions,
myArray.GetUpperBound(dimension) - the size of the array by the dimension dimension (from 0 to myArray.Rank-1).
Access to elements of multidimensional arrays and arrays of arrays is also carried out differently. Here you can read about the features of accessing array elements:
Arrays of arrays
Multidimensional arrays

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question