我正在尝试在循环中更新哈希表,但出现错误: System.InvalidOperationException: Collection was modified; 枚举操作可能无法执行。
private Hashtable htSettings_m = new Hashtable();
htSettings_m.Add("SizeWidth", "728");
htSettings_m.Add("SizeHeight", "450");
string sKey = "";
string sValue = "";
foreach (DictionaryEntry deEntry in htSettings_m)
{
// Get value from Registry and assign to sValue.
// ...
// Change value in hashtable.
sKey = deEntry.Key.ToString();
htSettings_m[sKey] = sValue;
}
有没有办法解决它,或者可能有更好的数据结构来实现这个目的?