Wednesday 21 September 2011

Resizing an Array

I have seen people declaring an array of fixed size. But sometimes while working on dynamic elements size this would be capable enough to hold all the elements in the array. But unfortunately it’s not true. Sometimes you need to handle with small set of data and sometimes with big set of data. Then, how to resize the array. So that it would be capable enough to hold this situation.

Simple:
The .NET Framework Version 2.0 introduced a solution to this problem by adding the

Array.Resize method, which is used to change the size of an array.

 Assume that, you have an array named firstArray initialized with five

Elements, you can extend its size to ten elements by using the following

statement:

Array.Resize (ref firstArray, 10);

This is very small method. but, very useful
See the example with the code below.


Thanks,
Md. Jawed