Hello
First, have a look at this C# code.. I am creating a 3 dimensional array and looping thru all its elements.
Seems fine doesnt it? Have a look at it again carefully... and then look at the Java code below. Notice the difference in foreach behavior.Code:int[, ,] myarray1 = new int[3, 2, 4] { { { 1, 2 , 10, 5}, { 3, 4, 0, 9 } } ,{ { 5, 6,4, 5 }, { 7, 8, 14, 9 }} ,{ { 6, 6, 2, 58}, { 2, 5, 77, 5 } } }; foreach (int x in myarray1) Console.WriteLine(x);
Code:int[][][] array = { { { 1, 2 , 10, 5}, { 3, 4, 0, 9 } } ,{ { 5, 6,4, 5 }, { 7, 8, 14, 9 }} ,{ { 6, 6, 2, 58}, { 2, 5, 77, 5 } } }; for(int[][] x : array) for(int[] y : x) for(int number : y) System.out.println(number);
Can someone explain this? The Java version is more mathematically correct, but then again the C# version is more "clean". Personally, I prefer the Java version because thats how it really should be... can someone tell me how I can achieve the similar thing in C#?


Reply With Quote


Bookmarks