两者都可以通过 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. Angularjs循环二维数组

    <div ng-app> <div ng-controller="test"> <div ng-repeat="links in slide ...

  2. jq中的css-Dom

    1,height() ,width() 此方法用来获取匹配元素的高和宽的值,如果括号内有值,则是修改匹配元素的值, 2.offset() 此方法的作用是获取元素在当前视窗的相对偏移,其中返回的对象包含 ...

  3. 离线dfs CF div2 707 D

    http://codeforces.com/contest/707/problem/D 先说一下离线和在线:在线的意思就是每一个询问单独处理复杂度O(多少多少),离线是指将所有的可能的询问先一次都处理 ...

  4. java war 打包、解压命令

    经常将工程打包成war包,打包如下: // 将当前目录打包成war包 jar cvf temp.war . 命令格式: java cvf 打包文件名称 要打包的目录 打包文件保存路径 解压自然就是: ...

  5. Android] Android XML解析学习——方式比较

     [Android] Android XML解析学习——方式比较 (ZT)  分类: 嵌入式 (From:http://blog.csdn.net/ichliebephone/article/deta ...

  6. SDAU课程练习--problemE

    problemE 题目描述 "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" "@ ...

  7. HDU 1896 Stones(优先队列)

    还是优先队列 #include<iostream> #include<cstdio> #include<cstring> #include<queue> ...

  8. Hadoop webHDFS设置和使用说明

    1.配置 namenode的hdfs-site.xml是必须将dfs.webhdfs.enabled属性设置为true,否则就不能使用webhdfs的LISTSTATUS.LISTFILESTATUS ...

  9. Python3基础 使用list() 生成一个空列表

    镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...

  10. c# 动态产生控件 注册动态控件事件

    用CheckEdit演示 其他控件类推 CheckEdit AllSele = new CheckEdit(); AllSele.Location = new System.Drawing.Point ...