Data Structures and Algorithms
with Object-Oriented Design Patterns in C#![]() ![]() ![]() ![]() ![]() |
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 .
The method first allocates
and initializes a new array of size m.
Next, it copies at most
elements from the old array
to the new array.
Therefore,
.