转换词典列出< KeyValuePair> [英] Convert dictionary to List<KeyValuePair>
本文介绍了转换词典列出< KeyValuePair>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道,它可能KeyValuePair列表转换成一个字典,但有一个快速的方法(除了通过手动循环)执行相反操作?
I know that its possible to convert a List of KeyValuePair into a Dictionary, but is there a quick way (besides looping through manually) to perform the vice versa operation?
这将是手动方式,
foreach (KeyValuePair<double,double> p in dict)
{
list.Add(new KeyValuePair<double,double>(p.Key,p.Value));
}
不是真的那么坏,但我只是好奇。
Not really that bad but I was just curious.
推荐答案
您的标题和你的问题是不一致的。
Your title and your question are inconsistent.
要转换词典< TKEY的,TValue>
到列表< KeyValuePair< TKEY的,TValue>>
你可以说
var list = dictionary.ToList();
或更详细的
var list = dictionary.ToList<KeyValuePair<TKey, TValue>>();
这是因为词典< TKEY的,TValue>
工具的IEnumerable< KeyValuePair< TKEY的,TValue>>
要转换清单< KeyValuePair< TKEY的,TValue>>
到词典< TKEY的,TValue>
你可以说
var dictionary = list.ToDictionary(x => x.Key, x => x.Value);
这篇关于转换词典列出< KeyValuePair>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文