日期:2009-12-31 浏览次数:20565 次
C#对象序列化和反序列化,如下代码示例:
- using System;
- using System.Text;
- using System.Collections.Generic;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- class SerializableOperate
- {
- private static void ObjectSerializable(object obj, string filePath)
- {
- FileStream fs = null;
- try
- {
- fs = new FileStream(filePath, FileMode.Create);
- BinaryFormatter bf = new BinaryFormatter();
- bf.Serialize(fs, obj);
- }
- catch (IOException ex)
- {
- Console.WriteLine("序列化是出错!");
- }
- finally
- {
- if (fs != null)
- {
- fs.Close();
- }
- }
- }
- private static object ObjectUnSerializable(string filePath)
- &