Appending it to a MemoryStream (per your subject line) is easy, just
call the Stream.Write method.
You can't append things to an array since arrays have a fixed length.
But you can create a new array and write both parts to it using
Array.Copy or Buffer.BlockCopy.
Others have suggested a MemoryStream. I won't. The reason is that it
will cause at least one extra array allocation than you need. Just
allocate the array yourself and use Buffer.BlockCopy, it is simple:
byte[] AppendArrays(byte[] a; byte[] b)
{
byte[] c = new byte[a.Length + b.Length]; // just one array
allocation
Buffer.BlockCopy(a, 0, c, 0, a.Length);
Buffer.BlockCopy(b, 0, c, a.Length, b.Length);
return c;
}
Richard
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.