using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization.Formatters.Binary;using System.Text;using System.Threading.Tasks;using System.IO;using 二进制序列化;namespace 反序列化{ class Program { static void Main(string[] args) { BinaryFormatter bf = new BinaryFormatter(); using (FileStream fs = new FileStream ("person.bin",FileMode.Open)) { object obj = bf.Deserialize(fs); People p = (People)obj; Console.WriteLine("姓名:{0}t年龄:{1}",p.Name ,p.Age); } Console.WriteLine("反序列化完毕!"); Console.ReadKey(); } }}复制代码###########################################
反序列化时需要引用People类所在的程序集