+ 1

Access Multidimensional Array from C#

This picture is taken from C# Intermediate, Multidimensional Array. https://lecontent.sololearn.com/material-images/cf857db26cea415cb0219fe792e02267-2422.png And this code is from the same module. Is the figure wrong to shows how to access an element in multidimensional array? In the code it use a comma (someNums[k, j]), but the figure is using 2 square brackets? https://sololearn.com/compiler-playground/cs988EkPZh1h/?ref=app

8th Mar 2024, 4:18 AM
Wong Hei Ming
Wong Hei Ming - avatar
3 Respuestas
+ 3
int[][,] is confusing as heck. I would not put such a structure even in the intermediate course. The multidim array with the comma syntax, is very much like a numpy array with rigid structure, like a matrix or cube. The jagged array is like a list of lists where each element can have a different length (or maybe a tuple of tuples would be more appropriate, because C# arrays cannot change their sizes dynamically). jagged example: https://sololearn.com/compiler-playground/c0lBVngq2GAi/?ref=app
8th Mar 2024, 10:46 AM
Tibor Santa
Tibor Santa - avatar
+ 1
It seems I ask too fast. A jagged array does use [][] to access the element. In the last page of jagged array, it asked for a jagged array which has 8 elements, and each element is a 2D array. int[][,] arr = new int[8][,] Is it similar to a python numpy 3d array, but each inner array can have different size?
8th Mar 2024, 4:51 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 1
Thanks for remind me that array in C# is fixed size.
8th Mar 2024, 1:44 PM
Wong Hei Ming
Wong Hei Ming - avatar