views:

311

answers:

1

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

+4  A: 

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
     );
Jon Skeet
Wow... I didn't even know that was possible. Guess I got a lot to learn ;)Thank you very much!
Christian Hubmann
John Sibly