如何以最短的方式将元组列表转换为字典(C#)?
IList<Tuple<long, int>> applyOnTree = getTuples();
假设long
是键,int
是值;
applyOnTree.ToDictionary(x => x.Item1, x => x.Item2);
显然,如果情况相反,只需将这两个位置调换即可。
使用 ToDictionary
扩展方法:
var dictionary = applyOnTree.ToDictionary(l => l.Item1, l => l.Item2);