【IT168技术文档】
通常情况下,我们应用哈西表都是根据Key值来快速得到值
但是有些时候,我们需要根据值来获得Key值,可以用如下方式获得:
''' <summary> ''' 根据哈西表中的Value值来获得Key值 ''' </summary> ''' <param name="value">value值</param> ''' <param name="pHash">哈西表</param> ''' <returns>key值的list</returns> ''' <remarks></remarks> Private Function GetHashKey(ByVal value As Object, ByVal pHash As Hashtable) As List(Of Object) Dim objectList As New List(Of Object) Dim pElementList As New List(Of IElement) Dim pEnumerator As IDictionaryEnumerator = pHash.GetEnumerator pEnumerator.Reset() pEnumerator.MoveNext() While 1 If value Is pEnumerator.Value Then pElementList.Add(pEnumerator.Key) objectList.Add(pEnumerator.Key) End If If Not pEnumerator.MoveNext() Then Exit While End While Return objectList End Function