Operating effect:
Code:
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 6 //introducing the appropriate namespaces7 usingSystem.Runtime.Serialization.Formatters.Binary;8 usingSystem.IO;9 Ten namespaceSerialization of One { A class Program - { - Static voidMain (string[] args) the { - //------------------------Serialize Method--------------------------------// - //Serialize Method: Serializing an object into a stream - //Graph: Object + //serializeationstream: Binary stream - //Serialize (Strwam serializeationstream, object graph); + A at - //------------------------Deserialize method--------------------------------// - //Deserialize method: deserializing a stream into an object - //serializeationstream: Binary stream - //Deserialize (Strwam serializeationstream); - in - to //declaring a String variable + stringGP ="Object"; - the //defining an object information * Objectobj = (Object) GP; $ Panax Notoginseng //Defining binary Instances -BinaryFormatter BF =NewBinaryFormatter (); the + //Create a memory flow store AMemoryStream ms =NewMemoryStream (); the + //serializing an object to a memory stream - BF. Serialize (MS, obj); $ $ //Sets the position in the current stream as the starting value -Ms. Seek (0, seekorigin.begin); - the //deserializing a memory stream into an object - Objectnewobj =BF. Deserialize (MS);Wuyi the //display content in a stream -Console.WriteLine ((string) newobj); Wu - //Close the stream About Ms. Close (); $ - Console.readkey (); - } - } A}
C #-Serialization and deserialization