C# Hash表简单操作

 

using System.Diagnostics;//必须命名空间

//实例化一个HashTable对象

Hashtable ht = new Hashtable();
Stopwatch sw = new Stopwatch();
object obj = new {
url="www.laibxw.com",
err="404"

};
sw.Start();

//添加100万条数据到hash表中
for (int i = 0; i < 1000000; i++)
{
ht.Add(i, obj+i.ToString());
}
var b = (from h in ht.Cast<DictionaryEntry>() select h).Take(10);
foreach (var a in b)
{
取值
Console.WriteLine(a.Value);

}
sw.Stop();
TimeSpan ts2 = sw.Elapsed;
Console.WriteLine("----开启插入完毕----");
Console.WriteLine("共耗时{0}", ts2.TotalMilliseconds);

posted on 2015-11-25 21:37  Andy_陈  阅读(315)  评论(0)    收藏  举报

导航