序列化和反序列化
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 序列化反序列化 { class Program { static void Main(string[] args) { //需要将对象的状态保存起来 持久化 //序列化:将对象的状态持久化到某种设备上(磁盘) //要将类标记为Serializable 这个类的对象才能被序列化 //以二进制的方式进行序列化,而不是文本文档 //反序列化:将之前序列化的文件还原为对象 #region[序列化] Person p1 = new Person() { Age = 19, Name = "Rose" }; System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); using (FileStream fs = new FileStream("se.bin", FileMode.Create)) {