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

时间:2010-03-03 19:55:31

标签: vb.net arrays dictionary string

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

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

并在其中查找值,如:

MessageBox.Show( dict["cat"] )

2 个答案:

答案 0 :(得分:6)

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

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

答案 1 :(得分:5)

在.NET 4.0中:

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