hashtabel與dictionary的區(qū)別-創(chuàng)新互聯

1 :hashtabel與dictio
nary的區(qū)別

Hashtable 支持多個線程讀, 同時只有一個線程寫 , dictionary 不支持

創(chuàng)新互聯是一家集網站建設,禹會企業(yè)網站建設,禹會品牌網站建設,網站定制,禹會網站建設報價,網絡營銷,網絡優(yōu)化,禹會網站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯網需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網站。

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<TKey, TValue>

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<string, int> pair in objHashTable)
//{
//    lblDisplay.Text = pair.Value + " " + lblDisplay.Text;
//}}

引用 dictionary :

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

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

分享文章:hashtabel與dictionary的區(qū)別-創(chuàng)新互聯
本文鏈接:http://muchs.cn/article18/dcjhdp.html

成都網站建設公司_創(chuàng)新互聯,為您提供關鍵詞優(yōu)化、Google軟件開發(fā)、營銷型網站建設網站策劃、建站公司

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯

h5響應式網站建設