In C, in array say A[2][3]
rightmost index change resulted in a smallest memory address shift, i.e. elements were located in memory as A[0][0], A[0][1]...
Is same is true for rectangular arrays in .NET? If we have, say array a[2, 3]
are elements located in memory as a[0, 0], a[0, 1]...
?
The data items in a multidimensional array are stored in the form of rows and columns. Also, the memory allocated for the multidimensional array is contiguous. So the elements in multidimensional arrays can be stored in linear storage using two methods i.e., row-major order or column-major order.
All the data items of an array are stored in consecutive memory locations in RAM. The elements of an array are of same data type and each item can be accessed using the same name.
A rectangular array of numbers is called a matrix. A matrix with n rows and p columns is referred as an n × p matrix. If a matrix has n rows and 1 column, it is called an n-dimensional column vector.
The CLI specification, section 8.9.1, states:
Array elements shall be laid out within the array object in row-major order (i.e., the elements associated with the rightmost array dimension shall be laid out contiguously from lowest to highest index). The actual storage allocated for each array element can include platform-specific padding.
So the answer is yes -- you will first encounter all elements of the first row, then all elements of the second row, etc (as the spec says, this is called row-major order).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With