【发布时间】:2011-01-10 05:00:25
【问题描述】:
我收到此错误: 哈希表插入失败。负载系数太高。 说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.InvalidOperationException:哈希表插入失败。负载系数太高。
在我的代码中,我会在字典中查找一个键,如果它不存在,我会添加它。经过一番研究,我认为上述错误是因为我试图添加相同的密钥两次。
static Dictionary<string, string> settings =
new Dictionary<string, string>();
if ((!settings.ContainsKey(Key)) || (settings[Key] == null))
settings.Add(Key, AltValue);//Changes by Reliance Consulting
有没有更安全的方法来做到这一点?
谢谢!
【问题讨论】:
-
是的,.Net 3.5 是框架
标签: .net multithreading dictionary