
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Reversing a Jagged Array
|
287
This method displays the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
3 ← Note that each row of 3 elements are reversed
2
1
6 ← This is the start of the next row
5
4
9
8
7
12
11
10
15
14
13
The Reverse2DimArray<T> method uses the same logic presented in the previous rec-
ipe to reverse the array; however, a nested
for loop is used instead of a single for
loop. The outer for loop iterates over each row of the array (there are five rows in the
someArray array). The inner for loop is used to iterate over each column of the array
(there are three columns in the
someArray array). The reverse logic is then applied to
the elements handled by the inner
for loop, which allows each row in the array to be
reversed.
See Also
See Recipes 5.2 and 5.4.
5.4 Reversing a Jagged Array
Problem
The Array.Reverse method does not provide a way to reverse each subarray in a
jagged array. You need this functionality.