I guess what I want to do is best explain via the codes here;
Byte[] byteA = new Byte[100000];
Byte[] byteB = new Byte[4];
...
...
...
Now I want to copy 4 bytes from certain portion of the byteA array.
In C/C++, this is what we do;
memcpy(byteB, byteA[X], 4);
Or
memcpy(byteB, byteA+X, 4);
But with C#, I had been stuck for a while with no luck....
Hope you understand what I wanted and could show me the way.
Thanks for your time. Sometime I wish Microsoft could create C# to be nearer
to C/C++. C# is still driving me headache...
balmerch - 04 Dec 2005 01:38 GMT
You could try:
public void CopyPartialByte(byte[] from, ref byte[] to, int index)
{
for (int x = index; x < (to.Length + index); x++)
to[x - index] = from[x];
}
Then call it:
CopyPartialByte(byteA, ref byteB, index);
Like usual this is off the top of my head, might be an error in the loop
counting but you get the idea I hope.
Chris
> I guess what I want to do is best explain via the codes here;
>
[quoted text clipped - 20 lines]
> Thanks for your time. Sometime I wish Microsoft could create C# to be nearer
> to C/C++. C# is still driving me headache...
Daniel O'Connell [C# MVP] - 04 Dec 2005 02:45 GMT
> You could try:
>
[quoted text clipped - 3 lines]
> to[x - index] = from[x];
> }
The ref shouldn't be needed here. An array is a reference type
You can also use Buffer.BlockCopy() to copy from arrays, look it up in MSDN
for the specifics.
EOS - 04 Dec 2005 09:08 GMT
Thanks! It is really easy to understand and to implement!
> You could try:
>
[quoted text clipped - 37 lines]
>> nearer
>> to C/C++. C# is still driving me headache...
Daniel Moth - 04 Dec 2005 01:40 GMT
See my reply to you in the PPC newsgroup
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
>I guess what I want to do is best explain via the codes here;
>
[quoted text clipped - 20 lines]
> Thanks for your time. Sometime I wish Microsoft could create C# to be
> nearer to C/C++. C# is still driving me headache...
Jon Skeet [C# MVP] - 04 Dec 2005 07:16 GMT
> I guess what I want to do is best explain via the codes here;
>
> Byte[] byteA = new Byte[100000];
> Byte[] byteB = new Byte[4];
<snip>
See Buffer.BlockCopy, and Array.Copy.

Signature
Jon Skeet - <skeet@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