被序列化的类: [Serializable] public class test1 { public string name; public double salary; public int age; } 序列化过程和反序列化: test1 t1 = new test1(); test1 t2 = new test1(); t1.name = "abc"; t1.salary = 2.3; t1.age = -1; IFormatter formatter = new BinaryFormatter(); Stream stream_write = new FileStream("c://myserializedata.bin", FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream_write, t1); stream_write.Close(); Stream stream_read = new FileStream("c://myserializedata.bin", FileMode.Open, FileAccess.Read, FileShare.Read); t2 = (test1)formatter.Deserialize(stream_read); stream_read.Close(); 被序列化的结果: