
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Writing a More Flexible StackTrace Class
|
289
This method displays the following:
1
2
3
10
11
12
13
14
15
3 ← The first reversed subarray
2
1
15 ← The second reversed subarray
14
13
12
11
10
The logic used to reverse each subarray of a jagged array is very similar to the rever-
sal logic discussed in the previous recipe. The
ReverseJaggedArray<T> method uses
the same basic logic presented in Recipe 5.2 to reverse each element in the array;
however, a nested
for loop is used instead of a single for loop. The outer for loop
iterates over each element of the first dimensioned array of the jagged array (there are
two elements in this array). The inner
for loop is used to iterate over each element
contained within the second dimensioned array of the jagged array. The reverse logic
is then applied to the elements handled by the inner
for loop. This allows each array
contained by the first dimensioned array in the jagged array to be reversed.
See Also
See Recipes 5.2 and 5.3.
5.5 Writing a More Flexible StackTrace Class
Problem
You have a StackTrace object that contains a listing of stack frames. You need to iter-
ate through these stack frames as if you were using a
Collection-type object.
Solution
Wrap the public interface of a StackTrace object to look like a Collection-type
object. The
StackTraceList class shown