Serialization in .NET

xiaoxiao2021-03-06  60

Using system.collections; using system.runtime.serialization; using system.runtime.serialization.formatters.binary;

A summary description description of Namespace Serialize {///

/// Class1. /// class class1 {/// /// The primary entry point of the application. /// [stathread] static void main (string [] args) {Person Person = New Person ("111", "Zhang San"); Person P = (Person) Person.clone (); stream sw = File.create ("personlist.bin"); system.Runtime.Serialization.formatters.binary.binaryformatter bf = new binaryformatter (); bf.serialize (sw, person); sw.close ();

Stream Sr = file.openread ("personlist.bin"); Person zhansan = (Person) bf.deSerialize (sr); console.writeline ("{0}, {1}, {2}, {3}", Person == ZHANSAN, P == Person, zhansan.id, zhansan.Name); console.readline ();}

[Serializable] public class person: iCloneable {public string id; public string name; public person () {} // public person (Person P) // {///} public person (String ID, String name) {this .id = id; this.name = name;} // public object clone () // {// Person Temp = new person () (); // Temp.id = this.id; // Temp.name = THIS. Name; //// Return Temp; //////} public object clone () {return this

}

}}}

转载请注明原文地址:https://www.9cbs.com/read-84309.html

New Post(0)