Cache.Item[String] 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定快取項目在指定的鍵值。
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
參數
屬性值
指定的快取項目。
範例
以下範例使用該 Item 特性來取得與 Key1 該鍵相關的快取物件值。 接著它會用該 HttpResponse.Write 方法將值值、介紹文字以及 B HTML 元素寫入網頁表單頁面。
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>")
以下範例示範使用此特性將文字框值插入快取。
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
備註
你可以利用這個屬性取得指定快取項目的值,或是將項目及其鍵加入快取。 使用該 Item[] 屬性新增快取項目等同於呼叫該 Cache.Insert 方法。