by gredman · 15y ago · 0 comments
When i reaches 2, two tabs have already been removed, so there is only one tab left. So in the loop body we then do:
this.MyControl.TabPages[2] // oh no!
In general, modifying a collection is a bit of a code smell, and a lot of iterator implementations will actually throw exceptions if you try it. var x = this.MyControl.TabPages.Count;
for ( int i=x ; i >0 ; i-- )
{
this.MyControl.TabPages.Remove ( this.MyControl.TabPages[i-1] );
}