c#遍历HashTable
2009-09-02 20:14
253 查看
foreach (System.Collections.DictionaryEntry objDE in objHasTab)
{
Console.WriteLine(objDE.Key.ToString());
Console.WriteLine(objDE.Value.ToString());
}
System.Collections.IDictionaryEnumerator enumerator = objHashTablet.GetEnumerator();
while (enumerator.MoveNext())
{
Console.WriteLine(enumerator.Key); // Hashtable关健字
Console.WriteLine(enumerator.Value); // Hashtable值
}
查看缓存项
Cache.Insert("key1", "key1");
Cache.Insert("key2", "key2");
Cache.Insert("key3", "key3");
StringBuilder sb = new StringBuilder();
sb.Append("缓存中的项数:").Append(Cache.Count.ToString() + "</br>");
foreach (DictionaryEntry Caches in Cache)
{
sb.Append("键:").Append(Caches.Key.ToString());
sb.Append("值:").Append(Caches.Value.ToString()).Append("</br>");
}
Response.Write(sb.ToString());
Cache.Remove("key1");
Cache.Remove("key2");
Cache.Remove("key3");
检索缓存项
string cachedString;
cachedString = (string)Cache["CacheItem"];
if (cachedString == null)
{
Response.Write("缓存项不存在,添加!");
cachedString = "Hello, World.";
Cache.Insert("CacheItem", cachedString);
}
说明:
(1) 通过在Cache对象中进行检查来确定该项是否不为null,如果该项存在,则将它分配给变量。否则,重新创建该项,将它添加到缓存中,然后访问它。
{
Console.WriteLine(objDE.Key.ToString());
Console.WriteLine(objDE.Value.ToString());
}
System.Collections.IDictionaryEnumerator enumerator = objHashTablet.GetEnumerator();
while (enumerator.MoveNext())
{
Console.WriteLine(enumerator.Key); // Hashtable关健字
Console.WriteLine(enumerator.Value); // Hashtable值
}
查看缓存项
Cache.Insert("key1", "key1");
Cache.Insert("key2", "key2");
Cache.Insert("key3", "key3");
StringBuilder sb = new StringBuilder();
sb.Append("缓存中的项数:").Append(Cache.Count.ToString() + "</br>");
foreach (DictionaryEntry Caches in Cache)
{
sb.Append("键:").Append(Caches.Key.ToString());
sb.Append("值:").Append(Caches.Value.ToString()).Append("</br>");
}
Response.Write(sb.ToString());
Cache.Remove("key1");
Cache.Remove("key2");
Cache.Remove("key3");
检索缓存项
string cachedString;
cachedString = (string)Cache["CacheItem"];
if (cachedString == null)
{
Response.Write("缓存项不存在,添加!");
cachedString = "Hello, World.";
Cache.Insert("CacheItem", cachedString);
}
说明:
(1) 通过在Cache对象中进行检查来确定该项是否不为null,如果该项存在,则将它分配给变量。否则,重新创建该项,将它添加到缓存中,然后访问它。
相关文章推荐
- C#遍历访问Dictionary和HashTable
- c#遍历HashTable
- C#中遍历Hashtable
- [转]c#遍历HashTable的方法
- c# hashTable的遍历【2种方法】与排序【3种方法】
- 如何在C#中遍历hashtable?
- C#遍历访问Dictionary和HashTable
- C#遍历访问Dictionary和HashTable
- [转载]C# HashTable 遍历与排序
- C#常见的几种集合 ArrayList,Hashtable,List<T>,Dictionary<K,V> 遍历方法对比
- C#遍历HashTable
- C#遍历访问Dictionary和HashTable
- setTimeout和setInterval的区别及用法、C#中遍历Hashtable对象[哈希表]的3种方法
- 黄聪:C#使用能够foreach对hashtable、List遍历时“集合已修改;可能无法执行枚举操作。”错误
- 在C#中怎样遍历Hashtable中的值
- C#中hashtable的赋值、取值、遍历、排序操作
- C#中HashTable的遍历
- C#中遍历Hashtable的4种方法
- C# 遍历Hashtable
- c#遍历HashTable