What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

Collection Modified

Ama

New Member
Joined
Jun 6, 2011
Messages
1,171
Reaction score
33
If I remove a node from a list, HB gives an error message. Everything works, just annoying error message. Not sure if the operation would even be used that much. I tried to send error report, but it failed.

Collection was modified; enumeration operation may not execute

Here is a snippet of code in question:
Code:
                foreach (Dispels d in DiscSettings.Instance.UrgentDispelList)
                {
                    if (d.ListItem.ToString().Equals(textBox1.Text))
                    {
                        DiscSettings.Instance.UrgentDispelList.Remove(d);
                    }
                }
 
You can't add/remove an item in a collection/list you are iterating over with foreach, because as soon as you do you fuck up the iterator because the list has changed. Either use a for loop and remove by index, or use a foreach loop and add the items you want to remove to a second list, then iterate over that and remove those items from the first list.

This is not an error with honorbuddy, this is an error with you not knowing enough about iterators and lists in c#.
 
Try this instead.
PHP:
 DiscSettings.Instance.UrgentDispelList.RemoveAll(d =>d.ListItem.ToString().Equals(textBox1.Text));
 
Thanks for info! Im still in school so this helps a lot.
 
linq is totally cheating if you don't understand why it was broek
 
Back
Top