using System;
// Reallocates an array with a new size,
// and copies the contents
// of the old array to the new array.
// Arguments:
// oldArray : the old array, to be reallocated.
// intnewSize : the new array size.
// Returns : A new array with the same contents.
public static Array resizeArray (Array oldArray, int intnewSize)
{
int intoldSize = oldArray.Length;
Type elementType = oldArray.GetType().GetElementType();
Array newArray = Array.CreateInstance(elementType,intnewSize);
int preserveLength = System.Math.Min(intoldSize,intnewSize);
if (preserveLength > 0)
Array.Copy (oldArray,newArray,preserveLength);
return newArray;
}