悬赏分:20 浏览:288 次
程序代码如下:
private IDictionary<string, BtsClass> btsClassList = new Dictionary<string, BtsClass>();
BtsClass tempClass = null;
if (!btsClassList.Keys.Contains(btsName))
{
tempClass = new BtsClass(btsName, 15);
tempClass.MaginDelegate += new MaginDelegate(BtsClass_MaginDelegate);
btsClassList[btsName] = tempClass;//这个地方,出现错误。。。
}
else
{
tempClass = btsClassList[btsName];
}
如上的代码,在标著的地方,出现了这样的错误:
System.IndexOutOfRangeException: 索引超出了数组界限。
在 System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
在 System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
实在是搞不明白,怎么会出现如上的错误....
请各位老大帮忙看看.
|
3个月前 颜昌钢 : 反编译查看了下Directory的代码: btsClassList.Add(btsName,tempClass); 与 btsClassList[btsName] = tempClass; 最终的不同在于调用 Insert(TKey key, TValue value, Boolean add) 这个方法传递的参数不同. 前一种方法的Boolean add 为true; 后一种方法的Boolean add 为false; 而唯一用到这个 参数的地方 只有一处: for (int i = this.buckets[index]; i >= 0; i = this.entries[i].next) { if ((this.entries[i].hashCode == num) && this.comparer.Equals(this.entries[i].key, key)) { if (add) { ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_AddingDuplicate); } this.entries[i].value = value; this.version++; return; } } 看了下,不管用哪种方法,似乎还是会存在 错误的可能.... |