SessionStateItemCollection.Item[] 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定集合中的值。
多載
| 名稱 | Description |
|---|---|
| Item[Int32] |
透過數值索引取得或設定集合中的值。 |
| Item[String] |
透過名稱取得或設定集合中的值。 |
Item[Int32]
透過數值索引取得或設定集合中的值。
public:
property System::Object ^ default[int] { System::Object ^ get(int index); void set(int index, System::Object ^ value); };
public object this[int index] { get; set; }
member this.Item(int) : obj with get, set
Default Public Property Item(index As Integer) As Object
參數
- index
- Int32
集合中值的數值索引。
屬性值
集合中儲存在指定索引的值。 若找不到指定的鍵,嘗試取得該鍵時會回傳 null,並嘗試設定該鍵,並建立一個新元素。
實作
範例
Important
使用這種類型的實例與不受信任的資料存在安全風險。 此物件僅用於受信任的資料。 如需詳細資訊,請參閱 驗證所有輸入。
以下程式碼範例以數值索引來設定並取得集合中的值 SessionStateItemCollection 。
SessionStateItemCollection sessionItems = new SessionStateItemCollection();
sessionItems["ZipCode"] = "98072";
sessionItems["Email"] = "someone@example.com";
for (int i = 0; i < items.Count; i++)
Response.Write("sessionItems[" + i + "] = " + sessionItems[i].ToString() + "<br />");
Dim sessionItems As SessionStateItemCollection = New SessionStateItemCollection()
sessionItems("ZipCode") = "98072"
sessionItems("Email") = "someone@example.com"
For i As Integer = 0 To items.Count - 1
Response.Write("sessionItems(" & i & ") = " & sessionItems(i).ToString() & "<br />")
Next
另請參閱
適用於
Item[String]
透過名稱取得或設定集合中的值。
public:
property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ name); void set(System::String ^ name, System::Object ^ value); };
public object this[string name] { get; set; }
member this.Item(string) : obj with get, set
Default Public Property Item(name As String) As Object
參數
- name
- String
集合中值的鍵名稱。
屬性值
集合中指定名稱的值。 若找不到指定的鍵,嘗試取得該鍵時會回傳 null,並嘗試設定該鍵,並建立一個新元素。
實作
範例
Important
使用這種類型的實例與不受信任的資料存在安全風險。 此物件僅用於受信任的資料。 如需詳細資訊,請參閱 驗證所有輸入。
以下程式碼範例依名稱設定並取得集合中的 SessionStateItemCollection 值。
SessionStateItemCollection items = new SessionStateItemCollection();
items["LastName"] = "Wilson";
items["FirstName"] = "Dan";
foreach (string s in items.Keys)
Response.Write("items[\"" + s + "\"] = " + items[s].ToString() + "<br />");
Dim items As SessionStateItemCollection = New SessionStateItemCollection()
items("LastName") = "Wilson"
items("FirstName") = "Dan"
For Each s As String In items.Keys
Response.Write("items(""" & s & """) = " & items(s).ToString() & "<br />")
Next