【发布时间】:2016-04-23 04:15:55
【问题描述】:
Public Sub Add(ByVal phone As String, ByVal name As String)
MyBase.InnerHashtable.Add(phone, name)
End Sub
'--Subroutine to extract the value from a dictionary when the key is passed as input
Public Function Item(ByVal phone As String) As String
Return CStr(MyBase.InnerHashtable.Item(phone))
End Function
示例条目:
'--Adding key and values to the dictionary
myDict.Add("6812036998", "Horton")
myDict.Add("6812036999", "Olive")
我需要帮助才能反向查找字典。鉴于key 我应该能够找到名称。但是,我下面的代码将无法正常工作,因为它是错误的。
Public Function lookupValue(ByVal name As String)
Return CStr(MyBase.InnerHashtable.Item(name))
End Function
【问题讨论】:
-
既然已经给出了
name,为什么还要在Dictionary中找到name。或者我想你想在给定key时找到name?
标签: .net vb.net visual-studio