Cache.Item[String] Proprietà

Definizione

Ottiene o imposta l'elemento della cache in corrispondenza della chiave specificata.

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

Parametri

key
String

Oggetto String che rappresenta la chiave per l'elemento della cache.

Valore della proprietà

Elemento della cache specificato.

Esempio

Nell'esempio seguente viene utilizzata la Item proprietà per recuperare il valore di un oggetto memorizzato nella cache associato alla Key1 chiave. Usa quindi il HttpResponse.Write metodo per scrivere il valore e il testo introduttivo e l'elemento HTML B in una pagina Web Form.

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>")

Nell'esempio seguente viene illustrato l'utilizzo di questa proprietà per inserire il valore di una casella di testo nella 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

Commenti

È possibile utilizzare questa proprietà per recuperare il valore di un elemento della cache specificato o per aggiungere un elemento e una chiave per tale elemento alla cache. L'aggiunta di un elemento della cache tramite la Item[] proprietà equivale a chiamare il Cache.Insert metodo .

Si applica a

Vedi anche