+ 1

Multi Dimension Array Length

int[,] arr = new int [4,4]; how to get length of each dmnsion array in c#? in java i can use: for(int i=0;i<arr.Length;i++){ for (int j=0;i<arr[0].Length;i++){ //do smthing } } but in c# i cant use arr[0].Length. help guys thx.

19th Nov 2017, 8:42 AM
Sonny Michael
Sonny Michael - avatar
3 Respostas
+ 7
It is because you used a multi dimensional array and not an array of arrays, so array[0] is forbidden array.Length work, but to access values of array, you have to do array[i,j] To get the length of the second dimension, you have to use arr.GetLength(1)
19th Nov 2017, 8:50 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 3
You're welcomed :)
19th Nov 2017, 8:55 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 2
thx man y'r awesome !
19th Nov 2017, 8:55 AM
Sonny Michael
Sonny Michael - avatar