Question: I have the following loop to remove the buttons in my C# Windows Forms application. The only problem is that it skips every other button. How do I go about removing all the button controls from my form?

```
foreach (Control cntrl in Controls)
{
    if(cntrl.GetType() == typeof(Button))
    {
        Controls.Remove(cntrl);
        cntrl.Dispose();
    }
}

```

Answer: 
I think this way is a bit more readable:

```
var controlsToRemove = Controls.OfType<Button>().ToArray();
foreach (var control in controlsToRemove)
{
    Controls.Remove(control);
    cntrl.Dispose();
}

```

Calling `ToArray()` makes a new concrete collection, so that you can enumerate over one and modify the other.
Youre iterating over the same collection from whitch youre removing. Use this code:

```
    List<Control> cleanControls = new List<Control>();
    foreach(Control ctr in Controls)
    {
       if(cntrl.GetType() != typeof(Button))
       {
          cleanControls.Add(ctr);
       }
       else
       {
         ctr.Dispose();
       }
    } 
    Controls = cleanControls;

```

That's It!
Hope I helped!