Creating an Array from a multidimensional array

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
 
A

Andre

Use System.Array.Copy

For example:

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


-Andre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top