M
Marius Cabas
I have a Byte[] array and I want to concatenate it to another Byte[] array.
How can I do this?
Thanks.
How can I do this?
Thanks.
Dennis Myrén said:You should create a new array and copy the data there:
byte [] array1 = new byte [3] { 0, 1, 2 };
byte [] array2 = new byte [3] { 4, 5, 6 };
byte [] concat = new byte [array1.Length + array2.Length];
Then, preferably use System.Buffer.BlockCopy to copy the data, since it is
a lot faster than System.Array.Copy:
System.Buffer.BlockCopy
(array1, 0, concat, 0, array1.Length);
System.Buffer.BlockCopy
(array2, 0, concat, 0, array2.Length);
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Marius Cabas said:I have a Byte[] array and I want to concatenate it to another Byte[]
array.
How can I do this?
Thanks.
Dennis Myrén said:Sorry;
System.Buffer.BlockCopy
(array1, 0, concat, 0, array1.Length);
System.Buffer.BlockCopy
(array2, 0, concat, 0, array2.Length);
should be:
System.Buffer.BlockCopy
(array1, 0, concat, 0, array1.Length);
System.Buffer.BlockCopy
(array2, 0, concat, array1.Length - 1, array2.Length);
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Dennis Myrén said:You should create a new array and copy the data there:
byte [] array1 = new byte [3] { 0, 1, 2 };
byte [] array2 = new byte [3] { 4, 5, 6 };
byte [] concat = new byte [array1.Length + array2.Length];
Then, preferably use System.Buffer.BlockCopy to copy the data, since it
is a lot faster than System.Array.Copy:
System.Buffer.BlockCopy
(array1, 0, concat, 0, array1.Length);
System.Buffer.BlockCopy
(array2, 0, concat, 0, array2.Length);
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
Marius Cabas said:I have a Byte[] array and I want to concatenate it to another Byte[]
array.
How can I do this?
Thanks.