Robin Rodricks
Robin Rodricks

Reputation: 113956

What's the easiest way to get Dictionary functionality in VB.NET?

I want to statically define a mapped array of strings like:

var dict = {cat:50, bat:10, rat:30};

and lookup values within it like:

MessageBox.Show( dict["cat"] )

Upvotes: 1

Views: 681

Answers (2)

Robert Harvey
Robert Harvey

Reputation: 180787

In .NET 4.0:

Dim d As Dictionary(Of String, Integer) From
    {{"cat", 50}, {"bat", 10}, {"rat",30 }} 

Upvotes: 5

Seth Moore
Seth Moore

Reputation: 3545

Dim dict As New Dictionary(Of String, Integer)()

With dict 
    .Add("Cat", 50)
    .Add("Bat", 10)
    .Add("Rat", 30)
End With

Upvotes: 6

Related Questions