Cache.GetEnumerator 方法

定义

检索用于循环访问缓存中包含的密钥设置及其值的字典枚举器。Retrieves a dictionary enumerator used to iterate through the key settings and their values contained in the cache.

public:
 System::Collections::IDictionaryEnumerator ^ GetEnumerator();
public System.Collections.IDictionaryEnumerator GetEnumerator ();
member this.GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
Public Function GetEnumerator () As IDictionaryEnumerator

返回

要循环访问 Cache 对象的枚举数。An enumerator to iterate through the Cache object.

示例

下面的示例使用IDictionaryEnumerator GetEnumerator方法创建CacheEnum对象。The following example creates an IDictionaryEnumerator object, CacheEnum, using the GetEnumerator method. 枚举器将遍历缓存, 将每个缓存项的值转换为字符串, 然后将这些值写入 Web 窗体页。The enumerator moves through the cache, converts the value of each cached item to a string, and then writes the values to a Web Forms page.

IDictionaryEnumerator CacheEnum = Cache.GetEnumerator();
while (CacheEnum.MoveNext())
{
  cacheItem = Server.HtmlEncode(CacheEnum.Current.ToString()); 
  Response.Write(cacheItem);
}
Dim CacheEnum As IDictionaryEnumerator = Cache.GetEnumerator()
While CacheEnum.MoveNext()
   cacheItem = Server.HtmlEncode(CacheEnum.Current.Value.ToString())
   Response.Write(cacheItem)
End While

注解

此方法枚举项时, 可以在缓存中添加或移除项。Items can be added to or removed from the cache while this method is enumerating through the items.

适用于