zoukankan      html  css  js  c++  java
  • 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)`
    
    考虑是否可以利用第三个参数做一些事情,有待验证
  • 相关阅读:
    go语言入门(三)
    go语言入门(二)
    Nand Flash 基础
    哈希技术
    NorFlash基础
    二阶构造模式
    C++基础知识汇总
    Arm寄存器介绍及汇编基础
    Linux Makefile详解
    Linux链接器脚本详解
  • 原文地址:https://www.cnblogs.com/ArvinZhao/p/6004390.html
Copyright © 2011-2022 走看看