Mister E Posted August 13, 2004 Posted August 13, 2004 Lets say I have a serialized struct called MyStruct, to write it out in binary form I know that I can do this: FileStream fileStream = new FileStream(@"C:\wow.dat",FileMode.Create); BinaryFormatter binaryFormatter = new BinaryFormatter( ); binaryFormatter.Serialize(fileStream, MyStruct); fileStream.Close();But lets say, instead of sending it to a file, I wanted to just serialize it directly into a byte[]. How could I do that? Thanks... Quote
Administrators PlausiblyDamp Posted August 13, 2004 Administrators Posted August 13, 2004 Easiest way is to use a MemoryStream BinaryFormatter binaryFormatter = new BinaryFormatter( ); byte[] b = new byte[100]; //make correct size MemoryStream ms = new MemoryStream(b); binaryFormatter.Serialize(ms, MyStruct); Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Mister E Posted August 13, 2004 Author Posted August 13, 2004 That's what I was looking for. Thanks much. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.