February 6th, 2013, 04:57 PM
im looking for a way to resize an array e.g. from myarray[10,10] to myarray[20,20] while preserving the contents , by all accounts the best way is to use the array.copy. i found a snippet of code on a answer elsewhere which says :-
how do i pass my array into it ?
public static void ResizeArray<T>(ref T[,] original, int cols, int rows)
T[,] newArray = new T[rows, cols];
//copy the contents of the old array to the new one
Array.Copy(original, newArray, original.Length);
//set the original to the new array
original = newArray;
Resize_array<int>( [,] myarray , new rows, newcols)
i can see how the swap works but what happens to the old array, does garbage collection dispose of it or should i be handling that.
Does anyone have a better more efficient way ?
Last edited by jonnydexter; February 6th, 2013 at 05:07 PM.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.