VB.NET HashMap等价

时间:2011-03-09 11:16:13

标签: vb.net hashmap

我正在尝试存储一组对象,我需要能够根据对象的特定属性在恒定时间内访问它们。我希望通过将对象添加到HashMap并使用我想要索引的属性作为键来实现此目的。在Java中是否有类似Java的HashMap对象,或者我应该使用其他东西吗?

更新:使用VB 2010,.NET 4

干杯

1 个答案:

答案 0 :(得分:20)

根据您的需要,您可以使用HashTableDictionary

像这样:

Dim dictionary As New Dictionary(Of String, Integer)
dictionary.Add("Dot", 20)
dictionary.Add("Net", 1)
dictionary.Add("Perls", 10)
dictionary.Add("Visual", -1)

Dim Hashtable As New Hashtable()
hashtable.Add("Area", 1000)
hashtable.Add("Perimeter", 55)
hashtable.Add("Mortgage", 540)

有关更多用法示例,请查看thisthis

<强>更新

但是,正如@Konrad Rudolph所说,最好将Dictionary用于多个reasons。 (在.NET 2.0和obove上)

感谢您的评论!