如何在vb.net上添加多维字典数据

时间:2017-03-22 16:30:18

标签: vb.net dictionary

Dim texts As New Dictionary(Of String, Dictionary(Of String, String))

如何将数据添加到上面的字典?

1 个答案:

答案 0 :(得分:3)

假设您使用visual studio,您应该在键入texts.Add(

时获得提示

enter image description here

密钥为String,值为Dictionary(Of String, String)。添加值的一种方法是预先声明一个新字典,然后添加它

Dim texts As New Dictionary(Of String, Dictionary(Of String, String))()

Dim innerEnglish As New Dictionary(Of String, String)()
innerEnglish.Add("A", "Antelope")
innerEnglish.Add("B", "Bear")
texts.Add("English", innerEnglish)

Dim innerLatin As New Dictionary(Of String, String)()
innerLatin.Add("O", "Oryx")
innerLatin.Add("U", "Ursa")
texts.Add("Latin", innerLatin)

他们可以这样键入

texts("Latin")("U") ' returns "Ursa"
texts("English")("B") ' returns "Bear"