两者都可以通过 KeyValuePair<TKey,TValue> 进行遍历,并且两者可以相互转换:

List<KeyValuePair<string,string>> list = new List<KeyValuePair<string, string>>();

list.Add(new KeyValuePair<string, string>("asdf1", "1"));

list.Add(new KeyValuePair<string, string>("asdf1", "1"));

list.Add(new KeyValuePair<string, string>("asdf1", "1"));

Dictionary<string, string> dictionary = list.ToDictionary(x => x.Key, x => x.Value);

list = dictionary.ToList();


> 但是,后者的Key是唯一的,序列中不能包含相同Key值,前者就没有这个要求了。
> 因此,在将前者转化为后者时,如果有相同的key值,就会报错。
> 此外,
> `Enumarable.ToDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)` 考虑是否可以利用第三个参数做一些事情,有待验证

List<KeyValuePair<TKey,TValue>> 与 Dictionary<TKey,TValue> 不同的更多相关文章

  1. C# KeyValuePair<TKey,TValue> 与 Dictionary<TKey,TValue> 区别

    KeyValuePair<TKey,TValue> 可以设置.查询的一对键值 是struct Dictionary<TKey,TValue> 可以设置.查询的多对键值的集合 总 ...

  2. .net源码分析 – Dictionary<TKey, TValue>

    接上篇:.net源码分析 – List<T> Dictionary<TKey, TValue>源码地址:https://github.com/dotnet/corefx/blo ...

  3. Dictionary<TKey, TValue> 类

    C# Dictionary<TKey, TValue> 类 Dictionary<TKey, TValue> 泛型类提供了从一组键到一组值的映射.字典中的每个添加项都由一个值及 ...

  4. C# .Net 中字典Dictionary<TKey,TValue>泛型类 学习浅谈

    一.综述: Dictionary<TKey,TValue>是在 .NET Framework 2.0 版中是新增的.表示键值对的集合,Dictionary<TKey,TValue&g ...

  5. c# 扩展方法奇思妙用基础篇五:Dictionary<TKey, TValue> 扩展

    Dictionary<TKey, TValue>类是常用的一个基础类,但用起来有时确不是很方便.本文逐一讨论,并使用扩展方法解决. 向字典中添加键和值 添加键和值使用 Add 方法,但很多 ...

  6. C# 字典 Dictionary<Tkey,Tvalue>

    最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来.我们都知道计算机技术发展日新月异,速度惊人的快,你我稍不留神,就会被慢慢淘汰!因此:每日不间断的学习是避免被 ...

  7. 巧用Dictionary<TKey,TValue>,完成客户需求

    前几天与客户沟通一个项目,客户对其中某个模块提了一个需求. 把从数据库中取出的对物品的统计重新拆分重新统计.鉴于用文字不能清除的表达需求,我将该需求画出来,便于理解. 需求如下图: 就是A,B,C D ...

  8. C#编程(五十三)----------字典Dictionary<TKey,TValue>

    字典 关键字:Dicitionary 说明: 必须包含命名空间System.Collection.Generic Dictionary里面的每一个元素都是一个键值对(由两个元组组成:键和值). 键必须 ...

  9. Dictionary<Tkey.TValue>与SortedList

    一.概述 表示Key/Value集合,可以添加删除元素,允许按Key来访问元素.是Hashtable的泛型等效类. 它需要一个相等实现来确定键是否相等,可以使用实现了IEqualityComparer ...

随机推荐

  1. 交换数组中两个元素的位置,元素包括key和value 一维数组

    /*author: yangyu@sina.cndescription: 交换数组中两个元素的位置,元素包括key和value,具体用法见下面的例子*/$arr = array(11=>'a', ...

  2. 利用htmlunit登陆带验证码图片的网站

    http://htsoft.org/html/y2011/822_using-htmlunit-landing-site-with-captcha-image.html 利用htmlunit登陆带验证 ...

  3. WiresShark 使用方法

    Wireshark(前称Ethereal)是一款功能强大的网络抓包分析工具,在我的工作中是不可或缺的一部分工具,往往在网络出现异常时,查看网络中的数据包,会豁然开朗.1.菜单栏  主菜单包括以下几个项 ...

  4. CF 675 div2C 数学 让环所有值变为0的最少操作数

    http://codeforces.com/contest/675/problem/C 题目大意: 给一个环,标号为1-n,然后能从n回到1.让这个环的值为0,最少需要的操作数是多少? 这道题目呀.. ...

  5. 原创:LoadTest系列之Local.testtings之Web Test

    在录制脚本后,需要对脚本进行回放,而在Loal.testting的Web Test设置中,可以设置脚本运行的次数,以及是否考虑think time等,如下图所示: 1. 双击Solution Item ...

  6. codeforces 665A Buses Between Cities

    简单题 #include<cstdio> #include<cstring> #include<cmath> #include<vector> #inc ...

  7. webapp之路--之ios上图标

    以前我们用过favicon在浏览器给网站进行身份标识,用法如下: <link href="http://image.feeliu.com/web/favicon.ico" r ...

  8. java fx example

    http://www.java2s.com/Tutorials/Java/JavaFX/1500__JavaFX_WebEngine.htm

  9. [iOS]C语言技术视频-12-指针变量练习二(数组打印)

    下载地址: 链接: http://pan.baidu.com/s/1mg7ZwUW 密码: p8e6

  10. PAT (Advanced Level) 1084. Broken Keyboard (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...