// // This file contains the C# code from Program 4.7 of // "Data Structures and Algorithms // with Object-Oriented Design Patterns in C#" // by Bruno R. Preiss. // // Copyright (c) 2001--2002 by Bruno R. Preiss, P.Eng. All rights reserved. // // http://www.brpreiss.com/books/opus6/programs/pgm04_07.txt // public class MultiDimensionalArray { private int[] dimensions; private int[] factors; private object[] data; public MultiDimensionalArray(params int[] args) { dimensions = new int[args.Length]; factors = new int[args.Length]; int product = 1; for (int i = args.Length - 1; i >= 0; --i) { dimensions[i] = args[i]; factors[i] = product; product *= dimensions[i]; } data = new object[product]; } // ... }