On Mon, 02 Jul 2007 18:59:23 -0700, news <wj****@hotmail.comwrote:
I have a two dimensional byte array
byte[,] byte_array = new byte[12,256];
Now I populate the 12 arrays each with 256 byte values.
I create a single dimension array
byte[] single_byte_array = new byte[256];
How do I copy one of the 256 byte arrays from the 2 dimension array
byte_array to single_byte_array?
As near as I can tell, you can only copy between arrays with the same rank
(same number of dimensions). So, no...you can't declare a two-dimensional
array and then copy from that to a one-dimensional array without iterating
through all array elements you want to copy.
That said:
I don't think it should be that big of a problem to do the iteration. I
presume that the Array.Copy() method is optimized to deal with larger
chunks of memory, but unless you have to do this a lot, and with a lot of
data, it's probably not a big deal to not be able to take advantage of
that.
Also, you could declare a one-dimensional array of one-dimensional arrays,
and then you would be able to do the copy, since you'd just select the
one-dimensional array you want to copy, and copy the whole thing. So your
code might look something like this:
byte[][] byte_array = new byte[12][256];
byte[] single_byte_array = new byte[256];
// make sure byte_array is initialized, of course
byte_array[1].CopyTo(single_byte_array, 0);
Pete