2014-10-31 70 views
0

裏面我VB.net中創建了一個字典上一個循環我添加了一個重點和項目列表中包含一個列表Vb.net訪問的項目列表中的一本字典

Dim dic As New Dictionary(Of String, List(Of Double)) 

然後。

dic.Add("Key1", New List(Of Double)) 

做一些東西,並添加項目的關鍵

Dic("Key1").Add(1.1078) 
Dic("Key1").Add(12.232) 
Dic("Key1").Add(33.365) 

列表我如何使用密鑰

Console.writeline(Dic.Item("Key1")(1)) 
訪問列表的價值

我試圖打印與Key1 相關的列表的索引1,但我碰到了一個崩潰

感謝 馬切達

+0

定義「崩潰」是否存在與其關聯的消息? – Plutonix 2014-10-31 17:38:36

+0

是的,但如果我做的Console.Writeline(Dic.Item(「Key1」))我得到結果「System.Collections.Generic.List'1 [System.double]這是什麼意思 – user2879397 2014-10-31 17:39:25

+0

崩潰味精是System.Collections .Generic.KeyNotFoundException – user2879397 2014-10-31 17:40:39

回答

0

你同時找到了答案。我只想補充一點,一個更安全的方法是使用TryGetValue

Dim list As List(Of Double) 
If dic.TryGetValue("Key1", list) Then 
    Console.WriteLine(list(0)) 
Else 
    Console.WriteLine("Key1 not found!") 
End If 
0

它是如此簡單。

dic("key1").item(1)