serialization of objects in C # (binary):
Namespace: Creating System.Runtime.Serialization.Formatters.Binary
/ * the two object to serilisierenden class * / class object
object1b = new object class (10, hello );
object class object2b = new object class (11, "world" ); create
/ * binary formatter * /
BinaryFormatter binForm = new BinaryFormatter ();
/ * both objects serialized to C : \\ foo.txt write * /
using (FileStream fs = new FileStream ( "C: \\ \\ test.txt" , FileMode.Create)) {
binForm.Serialize (fs, object1b) ;
binForm.Serialize (fs, object2b);}
/ * Create two new objects * /
object class object11b = null ;
object class object22b = null ;
/ * both objects deserialize * /
using (FileStream fs = new FileStream ( "C: \\ \\ test.txt" , FileMode.Open)) {
object11b = (object class) binForm.Deserialize (fs);
object22b = (object class) binForm.Deserialize (fs);}
/ * deserialized object data output * /
Console.WriteLine ( "Number: {0 } term: {1} ", object11b.integer1, object11b.string1);
Console.WriteLine (" Number: {0} term: {1} ", object22b.integer1, object22b.string1);
Alternative:
XML Serialization with SoapFormatter from the namespace System.Runtime.Serialization.Formatters.Soap
0 comments:
Post a Comment