0

When I am going to modify hashtable data it is giving me the exception."Collection was modified; enumeration operation may not execute"

Here is the code..

foreach (DictionaryEntry Item in hashtable)
{
switch(Item.key.ToString())
{
case "Color":
{
hashtable["Color"]="ffffff";
break;
}
case "Width":
{
hashtable["Width"]="40";
break;
}
}
}

My qustion is ,
Is there any other way to iterate through hashtable by using ' foreach ' so that I can modify iterating hashtable?

Edited by happygeek: fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by privatevoid
0

You could use a standard for loop:

for(int index=0; index < hashtable.Keys.Count; index++)
{
    switch(hashtable.Keys[index])
    {
    ...
    }
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.