两者都可以通过 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. PAT (Advanced Level) 1114. Family Property (25)

    简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...

  2. Kth order statistcs

    Selection: selection is a trivial problem if the input numbers are sorted. If we use a sorting algor ...

  3. Mercurial hg web server的配置

    在windows下安装tortoisehg-1.0.3-hg-1.5.3-x64.exe的版本控制工具后,克隆建立中心库后,启动web server,其他分库可以连接中心库进行pull但无法push. ...

  4. Android--->LinearLayout页面布局方式

    main.xml布局方式 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns ...

  5. jQuery之call()方法的使用

    最近在做项目时候,写了几行关于DOM操作的代码,在方法中使用了this,在后期重构的时候,想将这段分离出来做成一个方法. 最开始想的很简单,就直接分离出来使用方法名称调用即可. 但是实际操作的时候没有 ...

  6. CSS3中transform几个属性值的注意点

    transform(变形)是CSS3中的元素的属性,transform的属性值主要包括旋转rotate.扭曲skew.缩放scale和移动translate以及矩阵变形matrix 基本用法可以参考文 ...

  7. glibc

    http://www.cnblogs.com/vipzrx/p/3599506.html 原因 wheezy是2.13,编译android4.4 需要2.14的,报错如下: rebuilts/gcc/ ...

  8. git diff 差异对比

    转载原文: http://fsjoy.blog.51cto.com/318484/245465/ 1. 查看当前所有的更改情况.git status 结果有3部分,changes to be comm ...

  9. Javascript Jquery 中的数组定义与操作_子木玲_新浪博客

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...

  10. Quick Cocos2dx MVC初步

    今天看到了自己之前两年前写的一个地图编辑器, 写了不到一半就放弃了, 但是还是github上的小伙伴fork了, 真的感觉对不起那位伙计, 同时也鄙视一下一直以来懒得要死的自己, 希望这个demo不要 ...