Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Basic C# question
Message
From
05/07/2006 14:19:30
 
 
To
05/07/2006 13:42:17
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01133939
Message ID:
01133944
Views:
24
Hi!

I would use the second one because I think (I'm not sure) that otherwise it would be checked each time (this.TreeView1.Nodes.Count).

>This is a basic question to enhance my understanding.
>
>In a loop is the condition tokenized once and checked every time or is it calculated in every iteration?
>
>Take this example:
>
>for (int i = 0; i < this.TreeView1.Nodes.Count; i++)
>{
>}
>
>
>or is it more efficient (faster) to do:
>
>int nCount = this.TreeView1.Nodes.Count;
>for (int i = 0; i < nCount; i++)
>{
>}
>
>
>Granted, in a short loop it does not really matter as the time differences would be measured in microseconds but the principle of the thing is what I'm looking for.
>
>Every little bit of new knowledge on .NET helps :)
robert.oh.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform