3 ms·
Say we start with three tabs, so i goes 0, 1, 2. When i reaches 2, two tabs have already been removed, so there is only one tab left. So in the loop body we t
by gredman 15y ago
Say we start with three tabs, so i goes 0, 1, 2.
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.
- polshaw 15y agoOK, i didn't think through the code.. rather i meant to iterate downwards; var x = this.MyControl.TabPages.Count; for ( int i=x ; i >0 ; i-- ) { this.MyControl.TabPages.Remove ( this.MyControl.TabPages[i-1] ); }