我有以下代码迭代字典,如果键没有值,它会检查另一个字典的值并分配它。我不断收到以下异常。
- $exception {"Collection was modified; enumeration operation may not execute."} System.Exception {System.InvalidOperationException}
foreach (KeyValuePair<string, string> param in request.Field.StoredProcedure.Parameters)
{
if ((param.Value == null || param.Value.Length == 0) &&
request.SearchParams.ContainsKey(param.Key))
{
request.Field.StoredProcedure.Parameters[param.Key] =
request.SearchParams[param.Key];
}
else if (param.Value == null || param.Value.Length == 0)
{
throw new ArgumentException(
"No value could be found for sproc parameter " + param.Key);
}
}
在迭代集合时,您是否无法为集合分配值?