zoukankan      html  css  js  c++  java
  • C#Dictionary不能添加重复键的解决方法

    重载了一个方法:

     public class RepeatDictionaryComparer : IEqualityComparer<string>
        {
            public bool Equals(string x, string y)
            {
                return x != y;
            }
            public int GetHashCode(string obj)
            {
                return obj.GetHashCode();
            }
        }
    

      调用:

    Dictionary<string, string> _dic = new Dictionary<string, string>(new RepeatDictionaryComparer());
    

      这样重复的键也可以添加了。

    java中Map集合类:

    Map集合类                              Key                       Value                 Super          说明

    HashTable                         不允许为null            不允许为null      Dictionary    线程安全

    concurrentHashMap         不允许为null            不允许为null       AbstractMap   锁分段技术和CAS

    TreeMap                            不允许为null            允许为null         AbstractMap    线程不安全

    HashMap                          允许为null               允许为null          AbstractMap   线程不安全,resize死链问题

  • 相关阅读:
    MongoDB 之 手把手教你增删改查 MongoDB
    MongoDB 之 你得知道MongoDB是个什么鬼 MongoDB
    全栈12期的崛起之捡点儿有用的说说
    Python 常用模块
    Python3中的内置函数
    Python程序员之面试必回习题
    Django之初始庐山真面目
    Django之ORM操作
    MySQL-索引
    MySQL-函数
  • 原文地址:https://www.cnblogs.com/sunliyuan/p/11507686.html
Copyright © 2011-2022 走看看