title: C# SortedDictionary producing unusual results - Mk2
body: <p>I don't think I posted enough detail in the previous question and people seemed to stop responding so I'm reposting as we need to know why this problem is happening</p>
  
  <p>I'm working with a SortedDictionary and when we loop through it we get odd results.</p>
  
  <p>there is a lot of nesting involved and the final dictionary is actually the child of another dictionary which is the child of another!</p>
  
  <p>is the the complete nest.</p>
  
  <pre><code>SortedDictionary&lt;String, SortedDictionary&lt;String, SortedDictionary&lt;int, SortedDictionary&lt;String, String&gt;&gt;&gt;&gt;()
  </code></pre>
  
  <p>The dictionary i'm looping through is</p>
  
  <pre><code>SortedDictionary&lt;int, SortedDictionary&lt;String, String&gt;&gt;
  </code></pre>
  
  <p>And Here is the loop:</p>
  
  <pre><code>foreach (SortedDictionary&lt;String, String&gt; cDic in openTrades.Values)
  {
      String cTimestamp = convertTimestamp(cDic["open"]);
      if (!closeTrades.ContainsKey(cDic["key"]) &amp;&amp; barArray.ContainsKey(cDic["pair"]))
      {
            foreach (SortedDictionary&lt;String, String&gt; bDic in barArray[cDic["pair"]][cDic["frame"]].Values)
            {
                 //This is the relative Loop
            }
      }
  }
  </code></pre>
  
  <p>barArray is our Primary SortedDictionary (the subject of this question)
  openTrades is another SortedDictionary</p>
  
  <p>Now when we loop through the dictionary with an integer as an index we get varied results - IE. if we have 1,2,3,4 as the keys when looping through it may present them in this order: 4,2,1,3 which clearly doesn't make sense as this is meant to be a sorted dictionary.</p>
  
  <p>Any help as quickly as possible would be greatly appreciated as im stumped on this issue.
  Thanks
  James</p>