var rm = new ResourceManager(sometype);
var resourceSet = rm.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
I want to convert the above resource set into dictionary. Currently I'm doing through manually by looping as below.
var resourceDictionary = new Dictionary<string, string>();
foreach (var r in resourceSet)
{
var dicEntry = (DictionaryEntry)r;
resourceDictionary.Add(dicEntry.Key.ToString(), dicEntry.Value.ToString());
}
How I can do achieve that easily using linq?
Try this:
var resourceDictionary = resourceSet.Cast<DictionaryEntry>()
.ToDictionary(r => r.Key.ToString(),
r => r.Value.ToString());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With