4 ms·
What's wrong with the code, then, is that it was written under a little too much pressure for the developer to think clearly. for ( int i=0 ; i < this.MyCo
by qntm 15y ago
What's wrong with the code, then, is that it was written under a little too much pressure for the developer to think clearly.
for ( int i=0 ; i < this.MyControl.TabPages.Count ; )
{
this.MyControl.TabPages.Remove ( this.MyControl.TabPages[i] );
}
- AlexandrB 15y agoWhy not just: while (this.MyControl.TabPages.Count > 0) { this.MyControl.TabPages.Remove ( 0 ); }
- masklinn 15y agoVery inefficient on most array lists (but a very good idea on linked lists)
- tomjen3 15y agoHow many tabs do you use? Less than 50? Then don't worry about the optimization until you have to port it to a PDP10.
- tlrobinson 15y agowhile (this.MyControl.TabPages.Count > 0) { this.MyControl.TabPages.Remove ( this.MyControl.TabPages.Count-1 ); }
- hasslblad 15y agoOr Even this.MyControl.TabPages.Clear();
- qntm 15y agoIndeed. But the point I was making was that this hypothetical coder introduced more complexity by adding "i--;" whereas the code could equally well be fixed, in the same number of keystrokes, while reducing complexity, by removing "i++;".