Alex Rivera | Logout

Best way to combine two or more byte arrays in C#

Asked 2009-01-06T02:54:33.817
302

I have 3 byte arrays in C# that I need to combine into one. What would be the most efficient method to complete this task?

Edit
Report

1 Answer

6

The memorystream class does this job pretty nicely for me. I couldn't get the buffer class to run as fast as memorystream.

using (MemoryStream ms = new MemoryStream())
{
  ms.Write(BitConverter.GetBytes(22),0,4);
  ms.Write(BitConverter.GetBytes(44),0,4);
  ms.ToArray();
}
answered 2010-05-14T12:49:24.800

Your Answer