Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 字典构造函数:System.ArgumentException:已添加具有相同键的项_C#_Dictionary - Fatal编程技术网

C# 字典构造函数:System.ArgumentException:已添加具有相同键的项

C# 字典构造函数:System.ArgumentException:已添加具有相同键的项,c#,dictionary,C#,Dictionary,使用常规字典构造函数从另一个缓存初始化缓存。这是我第一次得到一份工作 System.ArgumentException:已添加具有相同密钥的项 私有字典缓存; 私有void updateCache(字典其他缓存) { cache=newdictionary(otherCache);//引发异常 } 我验证了cache和othercache确实具有相同的类型 这怎么可能 它不是,除非另一个缓存ha继承自允许重复的字典。您可以执行GroupBy键和计数,并查看哪个键导致它抛出吗?Linq在即时窗口

使用常规字典构造函数从另一个缓存初始化缓存。这是我第一次得到一份工作

System.ArgumentException:已添加具有相同密钥的项

私有字典缓存;
私有void updateCache(字典其他缓存)
{
cache=newdictionary(otherCache);//引发异常
}
我验证了cache和othercache确实具有相同的类型


这怎么可能

它不是,除非另一个缓存ha继承自允许重复的字典。您可以执行GroupBy键和计数,并查看哪个键导致它抛出吗?Linq在即时窗口中不起作用。我将尝试修改代码(不是我的代码)是的,您需要了解副本是如何进入
otherCache
的您是否检查过“otherCache”是否具有默认比较器?
private Dictionary<uint, Dictionary<ClassA, ClassB>> cache;
private void updateCache(Dictionary<uint, Dictionary<ClassA, ClassB>> otherCache) 
{
  cache = new Dictionary<uint, Dictionary<ClassA, ClassB>>(otherCache); // Raises the exception
}