[英]Convert list of Tuples to Dictionary
何以最短的方式將元組列表轉換為字典(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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.