ToDictionary 中的 KeyValuePair 解构

med*_*r44 3 .net c# linq

我可以像KeyValuePair在方法中那样解构为 lambda 参数吗?那么,是否有可能写这样的东西:ToDictionaryforeach

dict.ToDictionary((key, value) => key, (key, value) => 2*value);
Run Code Online (Sandbox Code Playgroud)

Fra*_*nin 5

不,你必须这样写:

var d = dict.ToDictionary(p => p.Key, p => p.Value * 2);
Run Code Online (Sandbox Code Playgroud)