2012-10-22 116 views
-1

您好我目前有一個集合容器,我需要將其內容轉儲到ArrayList或列表。這個ArrayList包含一個字典對象。如何將Collection <object>轉換爲ArrayList <Dictionary <string,string>>?

現在,如果我有這樣的事情我想這樣做ToList但它不工作

Collection<object> content = new Collection<object>(); 
....populate content container..... 
List <Dictionary<string, string>> lst = new List <Dictionary<string, string>>(); 
lst= (List< Dictionary<string, string> >) content.ToList(); 

我如何能做到這一點有什麼建議?

編輯: 我的內容集應該是一個包含地圖的列表。

+1

充滿詞典<字符串,字符串>集合而已? – CookieOfFortune

+3

集合中有什麼樣的對象?你想如何從中得到字符串? –

+0

是的集合填充Dictionary Murphy316

回答

4

你可以將它轉換爲字典,如果你願意,但你必須確保你做的運行時檢查...

lst = content.Cast<Dictionary<string, string>>().ToList(); 
+0

我不假設首先提及內容的索引值。索引值會告訴轉換哪個映射? – Murphy316

+0

哇,哇,什麼?請解釋清楚你要做什麼,因爲這完全改變了這個問題。 – CookieOfFortune

+0

剛剛編輯我的問題。這有幫助嗎? – Murphy316

相關問題