Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Basic C# question
Message
De
05/07/2006 14:53:28
 
 
À
05/07/2006 14:39:45
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01133939
Message ID:
01133955
Vues:
17
>Hmm, good question. I'm not sure that fundamentally there is any difference in your two snippets. Since it's possible that the code in the loop could change either this.TreeView1.Nodes.Count or nCount, then the question really boils down to whether the value is re-evaluated for each loop, or if it's fixed at the start of the first loop. I don't know the answer to that off the top of my head.
>
>It's probably infinitesimally quicker to use nCount instead of this.TreeView1.Nodes.Count, assuming there are enough loops to offset the overhead of declaring and initializing the extra variable. There could be a large speed gain if TreeView1 is an ActiveX; my understanding is that COM calls like that are expensive and that your second snippet is best practice in these cases.
>
>UPDATE: Docs for the C# FOR command:
>
>"The for loop executes a statement or a block of statements repeatedly until a specified expression evaluates to false."
>
>Seems to me, this means the logical expression is evaluated before each loop, not just once.



It is not COM but a standard .NET 2.0 TreeView. As I suppose it is evaluated every time it should be faster on the second example (variable).
Just wanted to confirm.

Thx.


Alex Feldstein, MCP, Microsoft MVP
VFP Tips: English - Spanish
Website - Blog - Photo Gallery


"Once again, we come to the Holiday Season, a deeply religious time that each of us observes, in his own way, by going to the mall of his choice." -- Dave Barry
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform