.NET 2
The standard:
foreach(KeyValuePair<int,int> entry in MyDic)
{
entry.Value += i; // does not work :(
i++;
}
Recommendations?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Loop over the
Keysproperty instead. When you use enumerators, any modification to the underlying collection invalidates the enumerator when it next callsMoveNext.You can enumerate the
KeysorAllKeys(which is just a string array) and modify the values they point to quite safely.Also, the properties of
KeyValuePair<K, V>are themselves read-only, so, iterator blocks or not, there’s no circumstances under which you could modify those values without abusing reflection.