序列化
MyObject obj = new MyObject();
obj.n1 = 1;
obj.n2 = 24;
obj.str = "一些字符串";
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("MyFile.bin", FileMode.Create,
FileAccess.Write, FileShare.None);
formatter.Serialize(stream, obj);
stream.Close();
反序列化
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("MyFile。bin", FileMode.Open,
FileAccess.Read, FileShare.Read);
MyObject obj = (MyObject) formatter.Deserialize(fromStream);
stream.Close();
```C#
##### 序列化标签
[Serializable] 对某个类进行序列化
[NonSerialized] 对某个字段不进行序列化
##### 读取xml文件
网友评论