title: Remove an object when in a for each loop
body: <p>I'm making a survival game and trying to remove an object when it goes off the screen. Here is the code:</p>
  
  <pre><code>Public Sub tmrEnemyMove_Tick(sender As Object, e As EventArgs) Handles tmrEnemyMove.Tick
      Dim koopaAnimation As Boolean
  
      For Each enemy As enemy In lstEnemy
          enemy.enemy.Left = enemy.enemy.Left - 20
  
          If enemy.enemy.Tag = "koopa" Then
              enemy.enemy.Image = Image.FromFile(Application.StartupPath + "\Graphics\koopa" + Trim(Str(koopaPosition)) + ".png")
              If koopaAnimation = False Then
                  If koopaPosition = 0 Then
                      koopaPosition = 1
                  Else
                      koopaPosition = 0
                  End If
              End If
              koopaAnimation = True
          End If
  
          If picMario.Left &lt; enemy.enemy.Left AndAlso enemy.enemy.Left &lt; picMario.Right Or picMario.Left &lt; enemy.enemy.Right AndAlso enemy.enemy.Right &lt; picMario.Right Then
              If picMario.Top &lt; enemy.enemy.Top AndAlso enemy.enemy.Top &lt; picMario.Bottom Or picMario.Top &lt; enemy.enemy.Bottom AndAlso enemy.enemy.Bottom &lt; picMario.Bottom Then
                  'MsgBox("Collision")
              End If
          End If
  
          If enemy.enemy.Left &lt; 0 Then
              lstEnemy.Remove(enemy)
              Me.Controls.Remove(enemy.enemy)
          End If
      Next
  End Sub
  </code></pre>
  
  <p>The error I get is:
  An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
  Additional information: Collection was modified; enumeration operation may not execute.</p>
  
  <p>If anyone could help that would be great, thanks.</p>