Question

I have a ResourceDictionary only containing string keys and string values. Now I want to have a Dictionary< string, string > with the same content.

How would you do that? Whats the fastest solution in C#?

Edit: Fastest in terms of perfomance ;)

Was it helpful?

Solution

Fastest in terms of simplest? Assuming .NET 3.5 (and thus LINQ) I'd use:

resourceDictionary.Keys.Cast<string>().ToDictionary
    (x => x,                             // Key selector
     x => (string) resourceDictionary[x] // Value selector
     );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top