• Visit Rebornbuddy
  • Collection Modified

    Discussion in 'Archives' started by Ama, Dec 13, 2011.

    1. Ama

      Ama New Member

      Joined:
      Jun 6, 2011
      Messages:
      1,171
      Likes Received:
      33
      Trophy Points:
      0
      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.

      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);
                          }
                      } 
       
    2. exemplar

      exemplar New Member

      Joined:
      Mar 16, 2010
      Messages:
      167
      Likes Received:
      32
      Trophy Points:
      0
      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#.
       
    3. highvoltz

      highvoltz Well-Known Member

      Joined:
      Mar 22, 2010
      Messages:
      1,729
      Likes Received:
      141
      Trophy Points:
      63
      Try this instead.
      PHP:
       DiscSettings.Instance.UrgentDispelList.RemoveAll(=>d.ListItem.ToString().Equals(textBox1.Text));
       
    4. Ama

      Ama New Member

      Joined:
      Jun 6, 2011
      Messages:
      1,171
      Likes Received:
      33
      Trophy Points:
      0
      Thanks for info! Im still in school so this helps a lot.
       
    5. exemplar

      exemplar New Member

      Joined:
      Mar 16, 2010
      Messages:
      167
      Likes Received:
      32
      Trophy Points:
      0
      linq is totally cheating if you don't understand why it was broek
       

    Share This Page