Thursday, December 18, 2008

Dictionaries - KeyValuePair

I needed to use a better collection.

I was working on a legacy framework using HashTables. My colleague suggested to rather use Dictionaries (since they are serializable). I then stumbles over this article explaining how using KeyValuePair is faster than using the regular Keys in a foreach loop. Read more here

Here's an example:
foreach (KeyValuePair pair in d)
{
Console.WriteLine(pair.Key + ", " + pair.Value.ToString());
}

No comments:

Post a Comment