0
点赞
收藏
分享

微信扫一扫

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

 



举报

相关推荐

0 条评论