Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Basic C# question
Message
From
05/07/2006 14:53:28
 
 
To
05/07/2006 14:39:45
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01133939
Message ID:
01133955
Views:
16
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform