我正在創建一個字典並將字符串添加爲鍵和另一個字典作爲引用特定用戶的值。 我無法迭代鍵(字典中的字符串),如果符合我的要求,我需要獲取該字典中的值。在C中迭代字典#
喜歡的東西:
Dictionary<string,Dictionary<string,string>> myDictionary = new Dictionary<string,Dictionary<string,string>>
mydictionary.Add(string,Dictionary<string,string>)
這裏就是我想要做的:
foreach(string s in Dictionary<string,Dictionary>)
{ if(s.contains("Foo")) {
return the dictionary which is mapped to this key.
}
}
使用'的foreach(字符串s在mydictionary.Keys)' – danludwig 2015-03-02 13:53:07
你確定使用字典是最好的方法?如果你只是想重複它,那麼可能有更好的選擇?取決於你當然在哪裏/如何使用它! – Belogix 2015-03-02 13:53:09
你想檢查's.ContainsKey(「foo」)'這也看起來很糟糕,爲什麼不使用具有屬性的類。 – 2015-03-02 13:53:19