I faced this problem twice. I had to merge 2 or more arrays to form another bigger byte array. So i wrote a method. This is it:
public byte[] MergeOneDimensionByteArrays(params byte[][] array)
{
int Length = 0;
for (int i = 0; i < array.Length; i++)
{
if (array[i] != null)
{
Length += array[i].Length;
}
}
byte[] bMain = new byte[Length];
int Current = 0;
for (int i = 0; i < array.Length; i++)
{
if (array[i] != null)
{
for (int j = 0; j < array[i].Length; j++)
{
bMain[Current] = array[i][j];
Current++;
}
}
}
return bMain;
}
I hope it helps.