Nen*_*nad 26 linq dictionary todictionary
是否简化了将list/enumberable转换KeyValuePair<T, U>
为Dictionary<T, U>
?
Linq转换,.ToDictionary()扩展无效.
Dam*_*ver 57
.ToDictionary(kvp=>kvp.Key,kvp=>kvp.Value);
Run Code Online (Sandbox Code Playgroud)
没有那么多工作.
JG *_* SD 10
您可以创建自己的扩展方法,该方法可以按预期执行.
public static class KeyValuePairEnumerableExtensions
{
public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source)
{
return source.ToDictionary(item => item.Key, item => item.Value);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16962 次 |
最近记录: |