-1

Hi I currently have a Collection container and I need to dump its contents into an ArrayList or a List. This ArrayList holds a dictionary object.

Now if I have something like this I tried doing ToList but it doesnt work

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();

Any suggestions on how I could do this ?

Edit: My content collection should be a list which contains a map.


You can cast it to Dictionary if you'd like, but you have to make sure you do the runtime checks...

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

1 に答える 1

4

必要に応じてディクショナリにキャストできますが、ランタイムチェックを必ず実行する必要があります...

lst = content.Cast<Dictionary<string, string>>().ToList();
于 2012-10-22T22:05:43.660 に答える