List<KeyValuePair<TKey,TValue>> 与 Dictionary<TKey,TValue> 不同
两者都可以通过
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> 不同的更多相关文章
- C# KeyValuePair<TKey,TValue> 与 Dictionary<TKey,TValue> 区别
KeyValuePair<TKey,TValue> 可以设置.查询的一对键值 是struct Dictionary<TKey,TValue> 可以设置.查询的多对键值的集合 总 ...
- .net源码分析 – Dictionary<TKey, TValue>
接上篇:.net源码分析 – List<T> Dictionary<TKey, TValue>源码地址:https://github.com/dotnet/corefx/blo ...
- Dictionary<TKey, TValue> 类
C# Dictionary<TKey, TValue> 类 Dictionary<TKey, TValue> 泛型类提供了从一组键到一组值的映射.字典中的每个添加项都由一个值及 ...
- C# .Net 中字典Dictionary<TKey,TValue>泛型类 学习浅谈
一.综述: Dictionary<TKey,TValue>是在 .NET Framework 2.0 版中是新增的.表示键值对的集合,Dictionary<TKey,TValue&g ...
- c# 扩展方法奇思妙用基础篇五:Dictionary<TKey, TValue> 扩展
Dictionary<TKey, TValue>类是常用的一个基础类,但用起来有时确不是很方便.本文逐一讨论,并使用扩展方法解决. 向字典中添加键和值 添加键和值使用 Add 方法,但很多 ...
- C# 字典 Dictionary<Tkey,Tvalue>
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来.我们都知道计算机技术发展日新月异,速度惊人的快,你我稍不留神,就会被慢慢淘汰!因此:每日不间断的学习是避免被 ...
- 巧用Dictionary<TKey,TValue>,完成客户需求
前几天与客户沟通一个项目,客户对其中某个模块提了一个需求. 把从数据库中取出的对物品的统计重新拆分重新统计.鉴于用文字不能清除的表达需求,我将该需求画出来,便于理解. 需求如下图: 就是A,B,C D ...
- C#编程(五十三)----------字典Dictionary<TKey,TValue>
字典 关键字:Dicitionary 说明: 必须包含命名空间System.Collection.Generic Dictionary里面的每一个元素都是一个键值对(由两个元组组成:键和值). 键必须 ...
- Dictionary<Tkey.TValue>与SortedList
一.概述 表示Key/Value集合,可以添加删除元素,允许按Key来访问元素.是Hashtable的泛型等效类. 它需要一个相等实现来确定键是否相等,可以使用实现了IEqualityComparer ...
随机推荐
- 基于IDL 的WebRS系统设计图
图1 用例图 图2 结构图
- Oracle Sql优化之Merge 改写优化Update
1.待改写语句如下 update table1 f )),) ,),)), f.jine2 )),) from table2 e where e.kjqj=f.kjqj=e.gs=f.gs and e ...
- AndroidGradle --多渠道打包配置(转发)
需求 国内Android app发布一般会有多个渠道,为了跟踪发展情况,通常会为每一个渠道定制一个特别的apk. 一般友盟之类第三方统计的渠道ID定义如下,以wandoujia为例 <meta- ...
- The Importance of Money in Life
What were you taught about money as you were growing up?something like "Money doesn't grow on t ...
- Chapter 1 First Sight——19
"I'm headed toward building four, I could show you the way…" Definitely over-helpful. &quo ...
- 保存iptables的防火墙规则的方法【转载】
转自: 保存iptables的防火墙规则的方法 - 51CTO.COMhttp://os.51cto.com/art/201103/249504.htm 保存iptables的防火墙规则的方法如下: ...
- springframwork历史版本下载地址
http://sourceforge.net/projects/springframework/files/springframework-2/
- i2c的时钟延展问题(转)
源:http://blog.csdn.net/zyboy2000/article/details/7636769 结论: (即在模拟i2c主:在主设置SCL为高后,要超时判断SCL是否为高,再发后面的 ...
- C#入门经典第七章,错误调试
调试模式下执行应用程序-------F5或是绿色的运行箭头 非模式下,调试---开始执行不调试(ctrl+F5)
- myeclipse导出javadoc时特殊字符 尖括号
源字符<?xml version="1.0" encoding="UTF-8" standalone="yes"?> javad ...