Creating an Array from a multidimensional array

  • Thread starter Thread starter
  • Start date Start date

Hi,

If Im using Jagged arrays, the following is possible:

int[][] arr = new int[10]

for(int i=0; i<10; i++) {
arr = new int[10];
}

int[] arrB = arr[3];

How can I achieve the same thing (i.e. create a single dimensional array
by assigning a copy of some row of a multidimensional array to it) using
multidimensional arrays? Also, in the last line above, a row is not
being assigned or copied by value right? A copy of the reference to the
4th row is being assigned to arrB? Thanks!

Oh and I dont want to use a For loop.. I mean, I don't want to do the
following:

int[] arrB = new int[arr.GetLength(0)];

for(int i=0; i<10; i++) {
arrB = arr[4, i];
}

Thanks

-Phil
 
Use System.Array.Copy

For example:

Array.Copy(arr, arr.GetLength(1)*4, arrB, 0, arr.GetLength(1));


-Andre
 
Back
Top