重载了一个方法:

 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死链问题

 

相关文章:

  • 2021-12-06
  • 2021-12-26
  • 2022-01-14
  • 2022-12-23
  • 2021-07-29
  • 2021-04-13
  • 2023-02-04
猜你喜欢
  • 2022-12-23
  • 2021-08-28
  • 2022-12-23
  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
相关资源
相似解决方案