反序列化
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary; //引入类库
using System.IO;
using ConsoleApplication6; //引入类所在的命名空间
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);
Person p = obj as Person;
Console.WriteLine(p.Name);
Console.WriteLine(p.Age);
Console.WriteLine(p.Email);
}
Console.WriteLine("ok");
Console.ReadKey();
}
}
}