通过Add方法可以将一个键值对添加到哈希表中,那么如何通过键取出值呢?

解决方案 »

  1.   

    这里有好几篇文章,其中就有HashTable示例:
    http://blog.csdn.net/ChengKing/category/150896.aspx
      

  2.   

    foreach(DictionaryEntry o in ht)
    {
    TextBox1.Text +="&"+o.Key.ToString ()+":"+o.Value .ToString ()+"&";
    }
      

  3.   

    ht[key]
    直接通过operator []
      

  4.   

    赋值:
    Hashtable hash = new Hashtable();
    hash["User"] = "sa";取值:
    string user = hash["User"];
    则user的值为"sa"
      

  5.   

    Dim ht As New Hashtable        ' .......        For Each key As String In ht.Keys
                Dim obj As Object = ht(key)
                ' 遍历操作
            Next
      

  6.   

    加入:hs.add("Key",obj)
    那么取出:XX=hs("Key")
      

  7.   

    遍歷hashtable最好的方式是
    hashtable.GetEnumerator
    返回IDictionaryEnumerator 
    然後可以用movenext等操作