//序列化 public static bool Serialize<T>(string file, T obj) { using (Stream stream = new FileStream(file, FileMode.Create, FileAccess.Write)) { IFormatter formater = new BinaryFormatter(); formater.Serialize(stream, obj); return true; } } //反序列化 public static T Deserialize<T>(string files) { T obj = default(T); using (Stream stream = new FileStream(files, FileMode.Open, FileAccess.Read)) { IFormatter formatter = new BinaryFormatter(); obj = (T)formatter.Deserialize(stream); return obj; } }