   remove the object in list
  It leads error....foreach (fireball fball in fireball_list)  { if (fball.position.X - fball.start_position.X >= 100f) {fireball_list.Remove(fball); }  }   
  That's probably because something is wrong.   ;Quote:Original post by Evil SteveThat's probably because something is wrong.=.=what's wrong...   ;Quote:Original post by tonaldQuote:Original post by Evil SteveThat's probably because something is wrong.=.=what's wrong...Maybe you should provide a little more information.;Quote:Original post by tonaldwhat's wrong...I don't know. What error do you get? Does it fail to compile? Does it crash at runtime? Does it cause you to get a blue screen of death? Does it cause your PC to burst into flames and lettuce to fall from the sky? What language is is in? What line does the error occur on? What does your debugger tell you is going on?   ;  It looks like C#, but if not then ignore the below.You need to give more detail, what are these lists of? Structs? In which case, there is your problem, structs are value types so you need to change your loop to account for this (or switch your struct to a class, but it may have performance implications).Failing that, what error are you getting exactly and where?   ;  You can't change a collection whilst you're iterating over it. Either store the elements to remove in another list then iterate over that one to remove them from the first list (a little hacky!) or use RemoveAll with a predicate:fireball_list.RemoveAll(fball => fball.position.X - fball.start_position.X >= 100f);Edit: Whoops, thought this was the .NET board as your code looks like C#.   ;  With a foreach you can not be removing items from the list or you break to the iterations.What you have to do if you want to do this.for(a = fireball_list.Count -1; a >=0; a--){if (fireball_list[a].position.X - fireball_list[a].start_position.X >= 100f){fireball_list.RemoveAt(a);}}That will do what you are wanting to do without breaking stuff.By starting at the end, you don't break the list as you are trying to iterate over it.theTroll   ;  thank you all of you.TheTroll's solution works!;  A helpful troll?  What is happening in the internet?theTroll   