Cache.Item[String] Propriedade

Definição

Obtém ou define o item cache na chave especificada.

public:
 property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ key); void set(System::String ^ key, System::Object ^ value); };
public object this[string key] { get; set; }
member this.Item(string) : obj with get, set
Default Public Property Item(key As String) As Object

Parâmetros

key
String

Um objeto que representa a chave para o item de String cache.

Valor de Propriedade

O item de cache especificado.

Exemplos

O exemplo seguinte utiliza a Item propriedade para recuperar o valor de um objeto em cache associado à Key1 chave. Depois, utiliza o HttpResponse.Write método para escrever o valor e o texto introdutório e o elemento B HTML numa página Web Forms.

Response.Write("Value of cache key: <B>" + Server.HtmlEncode(Cache["Key1"] as string) + "</B>");
Response.Write("Value of cache key: <B>" + Server.HtmlEncode(CType(Cache("Key1"),String)) + "</B>")

O exemplo seguinte demonstra o uso desta propriedade para inserir o valor de uma caixa de texto na cache.

private void cmdAdd_Click(Object objSender, EventArgs objArgs)
{
    if (txtName.Text != "")
    {
        // Add this item to the cache.
        Cache[txtName.Text] = txtValue.Text;
    }
}

Private Sub cmdAdd_Click(objSender As Object, objArgs As EventArgs)
  If txtName.Text <> "" Then
    ' Add this item to the cache.
  Cache(txtName.Text) = txtValue.Text
  End If
End Sub

Observações

Pode usar esta propriedade para recuperar o valor de um item de cache especificado, ou para adicionar um item e uma chave para ele à cache. Adicionar um item de cache usando a Item[] propriedade é equivalente a chamar o Cache.Insert método.

Aplica-se a

Ver também