Re: How to loop through Hashtable keys without using foreach
- From: Samuel R. Neff <samuelneff@xxxxxxxxxx>
- Date: Thu, 01 Feb 2007 15:28:16 -0500
The problem isn't the foreach but how you're using the data. You're
looping through the keys and then again looking up each value by key
which is waisteful. Instead do this:
foreach(DictionaryEntry de in ht) {
this.setProperty(de.Key, de.Value);
}
You may need some casting depending on how setProperty is declared.
In general you don't want to replace for-each loops with indexed
loops.
HTH,
Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On 1 Feb 2007 08:56:45 -0800, "Akira" <akira@xxxxxxxxxxxxx> wrote:
I noticed that using foreach is much slower than using for-loop, so I
want to change our current code from foreach to for-loop.
But I can't figure out how.
Could someone help me please?
Current code is here:
foreach ( string propertyName in ht.Keys )
{
this.setProperty( propertyName, ht[propertyName] );
}
.
- References:
- Prev by Date: Re: Best way to Read Binary Files
- Next by Date: Queueing in Client Server Application
- Previous by thread: Re: How to loop through Hashtable keys without using foreach
- Next by thread: Exception Handling and Class Inheritence
- Index(es):
Relevant Pages
|