c# dictionary及hashtable

前几天被人问到c#中dictionary和hashtable啥区别,貌似之前有过相似的疑问,今天看到这个博客不错,贴下结论:

参考 http://www.cnblogs.com/chengxingliang/archive/2013/04/15/3020428.html

1.HashTable大数据量插入数据时需要花费比Dictionary大的多的时间。

2.for方式遍历HashTable和Dictionary速度最快。

3.在foreach方式遍历时Dictionary遍历速度更快。

4、在单线程的时候使用Dictionary更好一些,多线程的时候使用HashTable更好。

    因为HashTable可以通过Hashtable tab = Hashtable.Synchronized(new Hashtable());获得线程安全的对象。

按照这个结论以后单线程还是用dictionary,但是遍历的话都用for,呵呵。

目前应该使用的GIS二次开发平台是VS2008,所以使用.net framework 4.0以上版本比较少。.net framework 4.0及其以上版本添加了 System.Collections.Concurrent 命名空间用于替代多线程中的System.Collections 及System.Collections.Generic 命名空间中的对应类型。详见:http://msdn.microsoft.com/zh-cn/library/system.collections.concurrent%28v=vs.100%29.aspx 。

posted @ 2013-06-28 15:06  nygfcn  阅读(257)  评论(0)    收藏  举报