Category Archives: Uncategorized

Dictionary with foreach

I’ve just want to mention how to do a foreach with a .NET 2.0 Hashtable:

[sourcecode lang=“c#“]Dictionary< string, int > dict = new Dictionary< string, int >();
dict[„one“] = 1;
dict[„two“] = 2;
dict[„thress“] = 3;

foreach( KeyValuePair< string, int > data in dict)
{
Debug.WriteLine( data.Key + “ => “ + data.Value );
}[/sourcecode] So this time KeyValuePair is our friend.