title: OrderedDictionary and Dictionary
body: <p>I was looking for a way to have my <code>Dictionary</code> enumerate its <code>KeyValuePair</code> in the same order that they were added. Now, <a href="http://msdn.microsoft.com/en-us/library/xfhwa508.aspx" rel="noreferrer">Dictionary's documentation</a> clearly states that:</p>
  
  <blockquote>
    <p>For purposes of enumeration, each item in the dictionary is treated as a <code>KeyValuePair&lt;TKey, TValue&gt;</code> structure representing a value and its key. The order in which the items are returned is undefined.</p>
  </blockquote>
  
  <p>I found out that what I needed was an <code>OrderedDictionary</code>, but being the sceptic that I am, I decided to try it myself:</p>
  
  <pre><code>OrderedDictionary od = new OrderedDictionary();
  Dictionary&lt;String, String&gt; d = new Dictionary&lt;String, String&gt;();
  
  for (int i = 0; i &lt; 10; i++)
  {
      od.Add("key" + i, "value" + i);
      d.Add("key" + i, "value" + i);
  }
  
  System.Console.WriteLine("OrderedDictionary");
  foreach (DictionaryEntry de in od) {
      System.Console.WriteLine(de.Key + ", " + de.Value);
  }
  
  System.Console.WriteLine("Dictionary");
  foreach (var tmp in d) {
      System.Console.WriteLine(tmp.Key + ", " + tmp.Value);
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>OrderedDictionary
  key0, value0
  key1, value1
  key2, value2
  ...
  
  Dictionary
  key0, value0
  key1, value1
  key2, value2
  ...
  </code></pre>
  
  <p>As you can see, both are ordered, and that raise two questions:</p>
  
  <p>In which case does the <code>Dictionary</code> give a different order that the one in which the values are added?
  Does my first <code>foreach</code> loop assure me to retrieve my <code>KeyValuePair</code> in the same order, or do I have to use the index?</p>