var rm = new ResourceManager(sometype);
var resourceSet = rm.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
Run Code Online (Sandbox Code Playgroud)
我想将上面的资源集转换为字典.目前我正在通过循环手动完成如下操作.
var resourceDictionary = new Dictionary<string, string>();
foreach (var r in resourceSet)
{
var dicEntry = (DictionaryEntry)r;
resourceDictionary.Add(dicEntry.Key.ToString(), dicEntry.Value.ToString());
}
Run Code Online (Sandbox Code Playgroud)
我如何使用linq轻松实现这一目标?
dtb*_*dtb 35
试试这个:
var resourceDictionary = resourceSet.Cast<DictionaryEntry>()
.ToDictionary(r => r.Key.ToString(),
r => r.Value.ToString());
Run Code Online (Sandbox Code Playgroud)