匯入命名空間:
using system.runtime.serialization.formatters.binary;
using system.io;
要序列化的類頭部記得加上標記[serializable]
序列化:
//定義檔案流
filestream fs=new filestream("file/info.bin",filemode.create);
//二進位制方式
binaryformatter bf=new binaryformatter();
//序列化儲存物件
bf.serialize(fs,這裡填要序列化的物件);
反序列化:
//定義檔案流
filestream fs=new filestream("file/info.bin",filemode.open);
//二進位制方式
binaryformatter bf=new binaryformatter();
//序列化儲存物件
物件=(物件型別)bf.deserialize(fs);
序列化和反序列化 C 序列化與反序列化。
序列化介紹 把物件用一種新的格式來表示。系列化只序列化資料。序列化不建議使用自動屬性 為什麼要序列化 將乙個複雜的物件轉換流,方便儲存與資訊交換。class program class person public int age 二進位制序列化 就是將物件變成流的過程,把物件變成byte class...
C 序列化和反序列化
binaryserialize serialize new binaryserialize book book serialize.deserialize book.write 3 測試用的 binaryserialize類 using system using system.collections...
C 序列化和反序列化
對stu類進行序列化和反序列化操作序列化所用到的stu類using system using system.collections.generic using system.linq using system.text public string stuname public int stuage ...