2016-07-29 33 views
0

我有這樣的名單:如何通過鍵入列表<詞典<字符串,字符串>>獲得價值在C#

List<Dictionary<string, string>> testList= new List<Dictionary<string, string>>(); 

因此,如何從每個字典的價值?

我知道我可以通過索引一樣得到解釋:

testList[index] 

但我不知道如何使用key從Dictionary得到的值。

+2

你試過testList [指數] [關鍵]? – Tobberoth

+0

哦,是的,作品謝謝!我想知道爲什麼沒有人有這個問題。我搜索了10分鐘沒有成功 – raymondis

+0

爲什麼downvote?.. – raymondis

回答

2

隨着

var value = testList[index][key] 

你會得到從列表內的字典中的值。

1

用途:

testList[int][TKey] 

Dictionary<object, object>有一個項目歡迎使用屬性Item[TKey]

testList[int].Add("apple", 1); 

if (testList[int].ContainsKey("apple")) 
{ 
    int value = testList[int]["apple"]; 
    Console.WriteLine(value); 
} 
相關問題