Re: Copying data between byte arrays

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



The length of the arrays should not cause any problems to Array.Copy; e.g.
the following copies the second 50 bytes of a 100 byte array into (roughly)
the middle of a 500 byte arraym then prints some of the contents to validate
this.

byte[] source = new byte[100];
for (int i = 0; i < 100; i++)
source[i] = (byte) i;
byte[] dest = new byte[500];
Array.Copy(source, 50, dest, 200, 50); // source array, source
start-offset, destination array, destination start-offset, items to copy
for (int i = 195; i < 255; i++)
Console.WriteLine("{0}: {1}", i, dest[i]);

If you are going to copy the entire source array, source.CopyTo(dest,offset)
is an easier option - again, it doesn't need the arrays to be the same size,
as long as there is sufficient space in the destination.

Did I miss something in your question?

Marc

"Vitaly Zayko" <vitaly_at_zayko_dot_net> wrote in message
news:uZDFFoy$FHA.4080@xxxxxxxxxxxxxxxxxxxxxxx
> It's probably simple but I can't find a way how to copy number of bytes
> from one byte array to another? Just like Array.Copy(SourceArray,
> SourceIndex, DestArray, DestIndex, Length) does but in my case the arrays
> have different length. Of course I can copy byte by byte but I guess there
> should be a function for such task.
> Thanks!
>
> --
> Vit Zayko


.



Relevant Pages

  • Re: Question about graph theroy--Help!
    ... the source and destination may be the same node. ... if it has visited that node before (loop). ... A data structure for a path would have: ... - fixed array of 254 bytes ...
    (comp.soft-sys.matlab)
  • Building an import routine
    ... integer equals the field count then delete the record. ... I?m considering creating an array of field names from the destination table, ... Trap error/acknowledge whether append is successful. ...
    (microsoft.public.access.externaldata)
  • Re: Cost of calling a standard library function
    ... > array which should be supplied as an address for both source and ... > destination. ... Please dont start that again? ... RosAsm support INFINITE ways to structure data. ...
    (alt.lang.asm)
  • Re: vb.net combine two byte arrays
    ... Ok I just dumped a test array to see what is the behavior you have. ... Source elements and then Destination elements rather than the other way ... >> the source array data/size etc. ... >> CompletedFile is the array to hold the two combined byte arrays and is ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Copy sub section of array of bytes to another array
    ... > to copy sub sections of an array from the middle. ... Copies bytes from a source to a destination. ... destination buffer, although it's possible that you may be copying ...
    (alt.comp.lang.borland-delphi)