foreach( KeyValuePair<string, string> kvp in dc ) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); }
When you loop a dictionary you use KeyValuePair that is generic. Since your dictionary contain the key as string and the value as string, this one will take also a string for both.
You can access the key with kvp.Key and the value with kvp.Value.
For your example, you are using a Dictionary of string that contain a value of KeyValuePair. So, you can have the exact print you want with :
foreach( KeyValuePair<string, KeyValuePair<string,string>> kvp in dc ) { Console.WriteLine(kvp.Key + " " + kvp.Value.Key + " "+ kvp.Value.Value); }
Tupleinstead of aKeyValuePair. But that's just me.KeyValuePairto store an old value of something in the key and the new value in value.Tuple<string, string>instead ofKeyValuePair<>(unless clearly you are recycling the KeyValuePair of another dictionary)struct Replacement<T> { public T OldValue { get; private set; } public T NewValue { get; private set; } ...and use that? I once spent several hours debugging code where some bozo had decided to store left, top, width and height of a rectangle in a struct with fields named left, top, right, bottom because he was too lazy to define a struct with the correct names. It was extremely difficult to debug because half the names were wrong.