I am sure that my in my hashtable, there is no duplicated value and key.
Here is my code:
private void checkclientleave(string content)
{
if (content == "I am leaving the room")
{
foreach (DictionaryEntry dict in clientsInroom)
{
if (dict.Value == clientSocket)
clientsList.Remove(dict.Key);
}
}
}
The value of my hashtable is the socket for each client.
The key of my hashtable is the name of each client.
I got some unknown error: collection was modified enumeration operation may not execute
Anyone has any idea??
That’s not an unknown error – that’s a well-documented error:
And for
MoveNext:You’re iterating over a dictionary, and you can’t add or remove entries while you’re iterating. If you know that you won’t have any other values, you can just return from your method as soon as you’ve found the key which matches the given value:
Another alternative would be to use LINQ: