在VB.NET中获取字典功能的最简单方法是什么?

Rob*_*cks 1 vb.net arrays string dictionary

我想静态定义一个映射的字符串数组,如:

var dict = {cat:50, bat:10, rat:30};
Run Code Online (Sandbox Code Playgroud)

并在其中查找值,如:

MessageBox.Show( dict["cat"] )
Run Code Online (Sandbox Code Playgroud)

Set*_*ore 6

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

With dict 
    .Add("Cat", 50)
    .Add("Bat", 10)
    .Add("Rat", 30)
End With
Run Code Online (Sandbox Code Playgroud)


Rob*_*vey 5

在.NET 4.0中:

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