Copy single dimenstion into another array

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I load an excel spreadsheet into an object array, [row, columns]. What is the
best way to copy a row into a single array or arraylist?

Currently I just loop through each column and assign it to the new array.

xlData was poplulated from excel interop

tosData = new object [109];
for (int curCol = 1; curCol < 109; curCol++)
tosData[curCol - 1] = xlData[curRow, curCol];

Thanks
 
Use the static Method Array.Copy. Works like this:

Array array1 = new Array(); //source
Array array2 = new Array(); //destination
Array.Copy(array1, array2, array1.Length);

Then everything in array1 is now in array2. It will do most of the type
casting and boxing for you.
 
Back
Top