My users pass me an array of some type, say int[] or string[]. I can easily query the types of the elements via GetElementType, and I can find out how long the array was when i
This should work:
static void Resize(ref Array array, int newSize) { Type elementType = array.GetType().GetElementType(); Array newArray = Array.CreateInstance(elementType, newSize); Array.Copy(array, newArray, Math.Min(array.Length, newArray.Length)); array = newArray; }