hashtabel与dictionary的区别-创新互联

1 :hashtabel与dictio
nary的区别

Hashtable 支持多个线程读, 同时只有一个线程写 , dictionary 不支持

创新互联是一家集网站建设,禹会企业网站建设,禹会品牌网站建设,网站定制,禹会网站建设报价,网络营销,网络优化,禹会网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

Hashtable supports multiple reader threads with a single writer thread, while Dictionary offers no thread safety. If you need thread safety with a generic dictionary, you must implement your own synchronization or (in .NET 4.0) use ConcurrentDictionary

2 : hash table 只能用 key 引用, 而不能 foreach , dictionary 可以。

引用 hash table:

public void MethodHashTable()
{
    Hashtable objHashTable= new Hashtable();
    objHashTable.Add(1, 100);  // int    objHashTable.Add(2.99, 200); // float    objHashTable.Add('A', 300);// char    objHashTable.Add("4", 400);// string
    lblDisplay1.Text= objHashTable[1].ToString();
    lblDisplay2.Text= objHashTable[2.99].ToString();
    lblDisplay3.Text= objHashTable['A'].ToString();
    lblDisplay4.Text= objHashTable["4"].ToString();


// ----------- Not Possible for HashTable ----------
//foreach (KeyValuePair pair in objHashTable)
//{
//    lblDisplay.Text = pair.Value + " " + lblDisplay.Text;
//}}

引用 dictionary :

public void MethodDictionary()
  {
    Dictionary dictionary = new Dictionary();
    dictionary.Add("cat", 2);
    dictionary.Add("dog", 1);
    dictionary.Add("llama", 0);
    dictionary.Add("iguana", -1);

//dictionary.Add(1, -2);// Compilation Error  foreach (KeyValuePair pair in dictionary)
    {
        lblDisplay.Text= pair.Value + " " + lblDisplay.Text;
    }
  }

当前标题:hashtabel与dictionary的区别-创新互联
当前URL:http://csruizhi.cn/article/dcjhdp.html

其他资讯

Copyright © 2007-2024 成都优众联杰科技有限公司 All Rights Reserved 蜀ICP备2024116266号
友情链接: 成都企业网站设计 网站设计制作报价 成都网站设计 企业网站建设 泸州网站建设 手机网站制作 营销网站建设 网站建设方案 成都商城网站制作 宜宾网站设计 公司网站建设 成都企业网站建设 营销网站建设 企业网站设计 成都网站建设 定制网站建设多少钱 成都网站制作 重庆电商网站建设 网站制作 网站设计制作 上市集团网站建设 商城网站建设