Copy byte array to another byte array in C# -
there 2 byte arrays populated different values.
byte[] array1 = new byte[5]; byte[] array2 = new byte[5]; then, need array1 same values array2.
by typing array1 = array2 set references, not copy values.
what might solution?
edit:
all answers , solutions work. code first solution looks visually more descriptive particular case.
array1 = array2.toarray();
and
array1.copyto(array2, 0);
as
buffer.blockcopy(array2, 0, array1, 0, 5);
one solution courtesy of linq...
array1 = array2.toarray(); edit: not need allocate space array1 before using linq call. allocation array1 done within toarray(). more complete example below
byte[] array2 = new byte[5]; // set values array2 byte[] array1 = array2.toarray();
Comments
Post a Comment