共用方式為


SessionStateItemCollection.Serialize(BinaryWriter) 方法

定義

將集合的內容寫入 BinaryWriter

public:
 void Serialize(System::IO::BinaryWriter ^ writer);
public void Serialize (System.IO.BinaryWriter writer);
member this.Serialize : System.IO.BinaryWriter -> unit
Public Sub Serialize (writer As BinaryWriter)

參數

writer
BinaryWriter

BinaryWriter,用於將序列化集合寫入資料流或編碼字串。

範例

下列程式代碼範例會建立並填 SessionStateItemCollection 入集合,並使用 Serialize 方法將內容寫入檔案。

SessionStateItemCollection items = new SessionStateItemCollection();

items["LastName"] = "Wilson";
items["FirstName"] = "Dan";

System.IO.BinaryWriter writer = new System.IO.BinaryWriter(
  System.IO.File.Open(Server.MapPath("session_collection.bin"), System.IO.FileMode.Create));

items.Serialize(writer);

writer.Close();
Dim items As SessionStateItemCollection = New SessionStateItemCollection()

items("LastName") = "Wilson"
items("FirstName") = "Dan"

Dim writer As System.IO.BinaryWriter = New System.IO.BinaryWriter( _
  System.IO.File.Open(Server.MapPath("session_collection.bin"), System.IO.FileMode.Create))

items.Serialize(writer)

writer.Close()

備註

方法 Serialize 可用來將集合的內容 SessionStateItemCollection 寫入會話存放區。

若要從會話存放區擷取串行化 SessionStateItemCollection 物件,請使用 Deserialize 方法。

適用於

另請參閱