Data Structures and Algorithms with Object-Oriented Design Patterns in C#
next up previous contents index

MultiDimensionalArray Indexer

The elements of a multi-dimensional array are accessed using the get and set accessor methods of the MultiDimensionalArray indexer. For example, you can access the tex2html_wrap_inline60305 element of a three-dimensional array a like this:

value = a[i,j,k];
and you can modify the tex2html_wrap_inline60305 element like this:
a[i,j,k] = value;

Program gif defines an indexer that provides get and set accessors implemented using the GetOffset method. The GetOffset method takes a set of n indices and computes the position of the corresponding element in the one-dimensional array according to Equation gif. This computation takes O(n) time in the worst case, where n is the number of dimensions. Consequently, the running times of the get and set accessors are also O(n).

   program3086
Program: MultiDimensionalArray indexer.


next up previous contents index

Bruno Copyright © 2001 by Bruno R. Preiss, P.Eng. All rights reserved.