Cache.Item[String] プロパティ
定義
指定したキーのキャッシュ項目を取得または設定します。Gets or sets the cache item at the specified key.
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
パラメーター
プロパティ値
指定したキャッシュ項目。The specified cache item.
例
次の例では、プロパティを使用し Item
て、キーに関連付けられているキャッシュされたオブジェクトの値を取得し Key1
ます。The following example uses the Item
property to retrieve the value of a cached object associated with the Key1
key. 次に、メソッドを使用して、 HttpResponse.Write 値と概要テキストおよび B HTML 要素を Web フォームページに書き込みます。It then uses the HttpResponse.Write method to write the value and introductory text and the B HTML element to a Web Forms page.
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>")
次の例は、このプロパティを使用して、テキストボックスの値をキャッシュに挿入する方法を示しています。The following example demonstrates using this property to insert the value of a text box into the 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
注釈
このプロパティを使用して、指定したキャッシュ項目の値を取得したり、項目とキーをキャッシュに追加したりすることができます。You can use this property to retrieve the value of a specified cache item, or to add an item and a key for it to the cache. プロパティを使用してキャッシュ項目を追加 Item[] することは、メソッドを呼び出すことと同じです Cache.Insert 。Adding a cache item using the Item[] property is equivalent to calling the Cache.Insert method.