SessionStateItemCollection.Item[] Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets a value in the collection.
Overloads
Item[Int32] |
Gets or sets a value in the collection by numerical index. |
Item[String] |
Gets or sets a value in the collection by name. |
Item[Int32]
Gets or sets a value in the collection by numerical index.
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
Parameters
- index
- Int32
The numerical index of the value in the collection.
Property Value
The value in the collection stored at the specified index. If the specified key is not found, attempting to get it returns null
, and attempting to set it creates a new element using the specified key.
Implements
Examples
Important
Using an instance of this object with untrusted data is a security risk. Use this object only with trusted data. For more information, see Validate All Inputs.
The following code example sets and gets values in a SessionStateItemCollection collection by numerical index.
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
See also
Applies to
Item[String]
Gets or sets a value in the collection by name.
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
Parameters
- name
- String
The key name of the value in the collection.
Property Value
The value in the collection with the specified name. If the specified key is not found, attempting to get it returns null
, and attempting to set it creates a new element using the specified key.
Implements
Examples
Important
Using an instance of this object with untrusted data is a security risk. Use this object only with trusted data. For more information, see Validate All Inputs.
The following code example sets and gets values in a SessionStateItemCollection collection by name.
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