Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET HashMap equivalent

Tags:

hashmap

vb.net

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 use something else?

Update: Using VB 2010, .NET 4

Cheers

like image 523
Andrew Avatar asked Mar 09 '11 11:03

Andrew


1 Answers

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!

like image 73
Morvader Avatar answered Sep 21 '22 08:09

Morvader