如何将Collection <object>转换为ArrayList&lt;字典<string,string =“”>&gt;?</string,> </object>

时间:2012-10-22 22:02:22

标签: c#

您好我目前有一个Collection容器,我需要将其内容转储到ArrayList或List中。此ArrayList包含字典对象。

现在,如果我有这样的东西,我尝试做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 个答案:

答案 0 :(得分:4)

如果您愿意,可以将其强制转换为字典,但您必须确保执行运行时检查...

lst = content.Cast<Dictionary<string, string>>().ToList();
相关问题