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?

You could use a standard for loop:

for(int index=0; index < hashtable.Keys.Count; index++)
{
    switch(hashtable.Keys[index])
    {
    ...
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.