使用 Enumerable.Range() 填充字典的问题

New*_*bie 5 c# linq lambda enumerable

如果我做

for (int i = 0; i < appSettings.Count; i++)
{
   string key = appSettings.Keys[i];
   euFileDictionary.Add(key, appSettings[i]);
}
Run Code Online (Sandbox Code Playgroud)

它工作正常。

当我尝试使用相同的东西时

Enumerable.Range(0, appSettings.Count).Select(i =>
{
   string Key = appSettings.Keys[i];
   string Value = appSettings[i];
   euFileDictionary.Add(Key, Value);
}).ToDictionary<string,string>();
Run Code Online (Sandbox Code Playgroud)

我收到编译时错误

无法从用法推断方法“System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)”的类型参数。尝试明确指定类型参数。

任何的想法?

使用 C#3.0

谢谢

lep*_*pie 5

Enumerable.Range(0, appSettings.Count).Select(i =>
new  
{   
   Key = appSettings.Keys[i],
   Value = appSettings[i]
})
.ToDictionary(x => x.Key, x => x.Value);
Run Code Online (Sandbox Code Playgroud)