x


Copying a multidimensional array

I have 2 multidimensional array, both of the same size. I need to copy the content from one to another. Is there a better way for doing that than this one??

for(var i : int = 0; i < cols; i++) {
     for(var j : int = 0; j < rows; j++) {
          myArr1[i][j] = myArr2[i][j];
      }
}

EDIT: Im using JS.

more ▼

asked May 16 '12 at 06:36 PM

DarkSlash gravatar image

DarkSlash
41 12 14 16

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
System.Array.Copy (myArr1, myArr2, myArr1.GetLength(0)*myArr1.GetLength(1));
more ▼

answered May 16 '12 at 07:13 PM

Eric5h5 gravatar image

Eric5h5
81.5k 42 133 529

BCE0023: No appropriate version of 'System.Array.Copy' for the argument list '(Array, Array, System.Object)' was found.

Im using JS. I forgot to mention :)

May 16 '12 at 07:19 PM DarkSlash

So am I (it's obvious from your code). I guess you're not actually using multidimensional arrays, instead you are using Arrays of Arrays. Which is bad. ;) Use multidimensional arrays instead.

May 16 '12 at 07:30 PM Eric5h5

Looked in my code. Im using arrays of arrays. Im going to look how to change it! Thanks! :)

May 16 '12 at 07:35 PM DarkSlash
var myArr1 = new int[5, 5];
May 16 '12 at 07:53 PM Eric5h5

Why is it bad to use arrays of arrays?

There are some cases where it is useful...

May 16 '12 at 08:01 PM Tasarran
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1396
x373

asked: May 16 '12 at 06:36 PM

Seen: 594 times

Last Updated: May 16 '12 at 08:58 PM