November 21, 2005

Using Streams To Serialize Something to A Byte Array

Writing To A Stream Using A BinaryWriter
byte[] data;
MemoryStream stream = new MemoryStream();
BitWriter writer = new BitWriter(stream, System.Text.Encoding.ASCII);
writer.UseNetworkByteOrder = true;
bat.Serialize(writer);
stream.Flush();
stream.Close();
data = stream.ToArray();
return data;

No comments: