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 方法。

适用于

另请参阅