tags:

views:

335

answers:

2

I'm concatenating a large number of byte[] arrays in C#. If I were doing this for strings, I would use StringBuilder -- is there an equivalent class that would work for binary data in byte[] arrays?

+15  A: 

I don't think there is an exact equivalent, but you could get it done with a BinaryWriter:

http://msdn2.microsoft.com/en-us/library/system.io.binarywriter.aspx

MemoryStream m = new MemoryStream();
BinaryWriter writer = new BinaryWriter(m);
writer.write(true);
writer.write("hello");
writer.write(12345);
writer.Flush();
return m.ToArray();
JerSchneid
Precisely what I needed, thank you.
kdt
+1  A: 

Write them into a MemoryStream, perhaps using a StreamWriter/BinaryWriter. If endian-ness is an issue, some of the classes here might help

spender