0

How to iterate through jagged array?

int[][,] arr=new int[3][,]; arr[0]=new int[2,3]{{1,1,1},{2,2,2}}; arr[1]=new int[1,2]{{3,3}}; arr[2]=new int[3,3]{{4,4,4},{5,5,5},{6,6,6}}; design algorithm please

13th Aug 2017, 7:08 PM
Waseem Malik 🇵🇰
Waseem Malik 🇵🇰 - avatar
4 ответов
+ 3
Got it! Missed the comma: foreach(int[,] intArr in arr) { foreach(int num in intArr) { Console.WriteLine(num); } } This should work. Full code here: https://code.sololearn.com/cR23s2yLi42r
13th Aug 2017, 8:05 PM
Bagshot
Bagshot - avatar
+ 2
Something like: foreach(int[] intArr in arr) { foreach(int num in intArr) { Console.WriteLine(num); } } I don't know. This makes my head hurt. I try to stay away from jagged arrays if possible, they quickly become complex.
13th Aug 2017, 7:23 PM
Bagshot
Bagshot - avatar
+ 1
it's not working... i spent almost 2hours on it but results comes in the form of lots of errors :-(
13th Aug 2017, 7:28 PM
Waseem Malik 🇵🇰
Waseem Malik 🇵🇰 - avatar
0
@Bagshot thank you so much :-)
15th Aug 2017, 12:43 PM
Waseem Malik 🇵🇰
Waseem Malik 🇵🇰 - avatar