开发者

VB.NET HashMap equivalent

开发者 https://www.devze.com 2023-02-15 14:19 出处:网络
I\'m trying to store a set of objects and I need to be able to access them in constant time based on a particular property of the objects. I was hoping to do this by adding the objects to a HashMap an

I'm trying to store a set of objects and I need to be able to access them in constant time based on a particular property of the objects. I was hoping to do this by adding the objects to a HashMap and using the property that I want to index by as the key. Is there a HashMap object in VB like in Java, or should I u开发者_如何学Gose something else?

Update: Using VB 2010, .NET 4

Cheers


Depending on your needs you could use a HashTable or a Dictionary.

like this:

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)

Have a look at this and this for more usage examples.

UPDATE:

But, as @Konrad Rudolph says, its better to use a Dictionary for multiple reasons. (On .NET 2.0 and obove)

Thanks for the comment!

0

精彩评论

暂无评论...
验证码 换一张
取 消