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

Resizing an Array

 

The set accessor of the Length property provides the means to change the size of an array at run time. This method can be used both to increase and to decrease the size of an array.

The running time of this algorithm depends only on the new array length. Let n be the original size of the array and let m be the new size of the array. Consider the case where tex2html_wrap_inline60217. The method first allocates and initializes a new array of size m. Next, it copies at most tex2html_wrap_inline60221 elements from the old array to the new array. Therefore, tex2html_wrap_inline60223.


next up previous contents index

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