473,394 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

this is an easy one

I must be tired.

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?

This doesn't work

single_byte_array = byte_array[1];

So can it be done without iterating through all 256 characters?
Thank You,
Bill
Jul 3 '07 #1
3 1192
Are you ever using the array as a Jagged array or are you merely cataloging
12 arrays? If you simply are using the byte arrays, why not use some other
type of collection of arrays? Much nicer and easier to work with. Make
sense? If not, write back.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

************************************************
Think outside the box!
************************************************
"news" <wj****@hotmail.comwrote in message
news:P7******************************@comcast.com. ..
>I must be tired.

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?

This doesn't work

single_byte_array = byte_array[1];

So can it be done without iterating through all 256 characters?
Thank You,
Bill

Jul 3 '07 #2
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
Jul 3 '07 #3
news <wj****@hotmail.comwrote:
I must be tired.

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.
You don't have 12 arrays there - you have *one* array. If you want
twelve arrays, you'll need to do:

byte[][] byteArrays = new byte[12][];

That's actually an array of 12 byte array references, all of which will
be null to start with.
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?
Given the above, you could do singleByteArray = byteArrays[i]; as you
wanted - but be aware that that doesn't copy the array, it just sets
the singleByteArray variable's value to be the same reference as
byteArrays[i] - so changing the array via either variable will make the
change visible through the other variable too (because there's just the
one array involved).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 3 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Canon EOS | last post by:
Hi, I am really new in .net and pocket PC development. My background are purely C/C++/VC++. Have developed on Mobile Java for a year and felt completely insecure with it because all codes can...
2
by: Hal Vaughan | last post by:
I'm self taught and most of what I've been working on for the past several years has been entirely in Perl and Java. I've noticed that I can code about 5 times faster in Perl than Java, in part...
13
by: Ghislain Tanguay | last post by:
I have a compiled vb.net app and I want to give the user a choice to launch it from the start line command and pass it a parameter or not. How can I do that in my code? Is it possible? Ex. :...
6
by: Martin Bootsma | last post by:
I have a C question, which looks very easy, but no one here seems to know an easy answer. I have a function "powell" (from Numerical Recipes) which takes an argument of the type "double...
1
by: NevilleDNZ | last post by:
Hi, Apologies first as I am not a unicode expert.... indeed I the details probably totally elude me. Not withstanding: how can I convert a binary string containing UTF-8 binary into a python...
6
cjbrx3115
by: cjbrx3115 | last post by:
Hey everyone, I just bought a new Windows Vista (Home Premium) computer. My old computer, a Windows XP Professional, had all of my old documents, spreadsheets, etc. I was planing on using the Easy...
2
by: Ben | last post by:
I'm looking for a web application framework with a good interface to PostgreSQL. The app I'm developing is relatively simple, but I'm new to coding, so it needs to be easy. What I'm making is...
59
by: Kevin Walzer | last post by:
From the introduction to PyObjC, the Python-Objective-C bridge on Mac OS X: "As described in Objective-C for PyObjC users the creation of Objective-C objects is a two-stage process. To initialize...
2
by: Dr. Colombes | last post by:
Is there an easy scientific graphics (plotting) package for Python 2.5.1 running on Ubuntu Linux 7.1 ("Gutsy Gibbon")? A few years ago I used PyLab (a MatLab-like plotting module for Python) on...
14
by: Grant | last post by:
I've seen a couple of articles on the internet that VB.NET applications can be decompiled very easy. For those who have had experience with this, is it true? What steps can be taken to avoid...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.