序列化反序列化

2022-03-28 10:37:30 字數 994 閱讀 6093

using system;

using system.collections.generic;

using system.io;

using system.linq;

using system.text;

using system.threading.tasks;

namespace 序列化反序列化

;system.runtime.serialization.formatters.binary.binaryformatter bf = new system.runtime.serialization.formatters.binary.binaryformatter();

using (filestream fs = new filestream("se.bin", filemode.create))

#endregion

#region【反序列化】

system.runtime.serialization.formatters.binary.binaryformatter bf2 = new system.runtime.serialization.formatters.binary.binaryformatter();

using (filestream fs = new filestream("se.bin", filemode.open))

#endregion

#region [將乙個物件儲存到檔案文字中,用檔案的方式讓物件持久化,但是麻煩]

person p = new person();

if (file.exists(@"1.txt"))

else);}

#endregion

console.read();}}

[serializable]//表示這個物件可以被序列化,裡面的成員如果有其它類,那麼這個類也應該需要標記serializable

public class person

public string name }}

序列化反序列化

只要用到網路開發啊,就一定會用到序列化反序列化。1,自定義結構體 struct test int len int type char data 10 test data test buffer.缺點 明文,只支援基本型別,不支援變長結構 2,在1的基礎上,自定義乙個緩衝類,存放乙個訊息。把訊息寫入緩...

序列化和反序列化 C 序列化與反序列化。

序列化介紹 把物件用一種新的格式來表示。系列化只序列化資料。序列化不建議使用自動屬性 為什麼要序列化 將乙個複雜的物件轉換流,方便儲存與資訊交換。class program class person public int age 二進位制序列化 就是將物件變成流的過程,把物件變成byte class...

序列化和反序列化

先定義乙個類 serializable xmlroot shintech public class person set public string name set public person this 0,string.empty public person int m age,string m...