Problem : You need to serialize data to a buffer in memory, rather than a network stream or file.
Solution: The preceding serialization example did this, but I’ll cover it in this section as well.
Serialize Objects Using SerializableAttribute
byte bytes = new byte;
using (MemoryStream ms = new MemoryStream(bytes))
//write to stream using any method you like that accepts a stream
//manipulate the bytes however you want, including converting them to
//text using the Encoding class if the data is textual