SessionStateItemCollection.Item[] Propriedade
Definição
Obtém ou define um valor na coleção.Gets or sets a value in the collection.
Sobrecargas
| Item[Int32] |
Obtém ou define um valor na coleção por índice numérico.Gets or sets a value in the collection by numerical index. |
| Item[String] |
Obtém ou define um valor na coleção por nome.Gets or sets a value in the collection by name. |
Item[Int32]
Obtém ou define um valor na coleção por índice numérico.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
Parâmetros
- index
- Int32
O índice numérico do valor na coleção.The numerical index of the value in the collection.
Valor da propriedade
O valor na coleção armazenada no índice especificado.The value in the collection stored at the specified index. Se a chave especificada não for encontrada, tentar obtê-la retornará null e tentar de defini-la criará um novo elemento usando a chave especificada.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.
Implementações
Exemplos
Importante
Usar uma instância deste objeto quando você tiver dados não confiáveis é um risco à segurança.Using an instance of this object with untrusted data is a security risk. Use esse objeto somente quando você tiver dados confiáveis.Use this object only with trusted data. Para obter mais informações, confira Validação de dados.For more information, see Data Validation.
O exemplo de código a seguir define e obtém valores em uma SessionStateItemCollection coleção por índice numérico.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
Aplica-se a
Item[String]
Obtém ou define um valor na coleção por nome.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
Parâmetros
- name
- String
O nome da chave do valor na coleção.The key name of the value in the collection.
Valor da propriedade
O valor na coleção com o nome especificado.The value in the collection with the specified name. Se a chave especificada não for encontrada, tentar obtê-la retornará null e tentar de defini-la criará um novo elemento usando a chave especificada.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.
Implementações
Exemplos
Importante
Usar uma instância deste objeto quando você tiver dados não confiáveis é um risco à segurança.Using an instance of this object with untrusted data is a security risk. Use esse objeto somente quando você tiver dados confiáveis.Use this object only with trusted data. Para obter mais informações, confira Validação de dados.For more information, see Data Validation.
O exemplo de código a seguir define e obtém valores em uma SessionStateItemCollection coleção por nome.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