In Java you'd use a ByteArrayOutputStream to write to, then call its toByteArray() method. There is no such equivalent in C# I noticed.
You could write to a StringWriter, then convert the
string into a byte[] somehow. Or you could put each byte into a List<byte> (yes people, this is allowed in C#
), then convert that into a byte[].