List of Dictionary to List of another Dictionary

I have a huge list of Dictionary like

List<Dictionary<String,SomeType>> Dict = new List<Dictionary<string,SomeType>>();

I need to convert to the list of dictionary of some other type like below:

List<Dictionary<String,SomeOtherType>> AnotherDict;

Is there a better approach than foreach on the 'Dict' List.

Jon Skeet
people
quotationmark

Yes, you can use LINQ:

AnotherDict = Dict.Select(d => d.ToDictionary(pair => pair.Key,
                                              pair => Convert(pair.Value)))
                  .ToList();

Where Convert is whatever conversion you want to apply to SomeType to construct a SomeOtherType.

EDIT: As noted in comments, this is no more efficient than using nested foreach loops yourselves. It's just simpler.

people

See more on this question at Stackoverflow