title: Iterate over a nested dictionary
body: <p>I'm trying to iterate through the following nested dictionary instance:</p>
  
  <pre class="lang-cs prettyprint-override"><code>Dictionary&lt;String, Dictionary&lt;Datetime, int&gt;&gt; nestedDictionary =
      new Dictionary&lt;String, Dictionary&lt;Datetime, int&gt;&gt;()
  </code></pre>
  
  <p>The goal is to iterate through all integers in the dictionary. 
  To iterate over the dictionary instance I use a nested <code>foreach</code> loop, as shown below:</p>
  
  <pre class="lang-cs prettyprint-override"><code>int highestTargetInConstraint = 0;
  foreach(String key1 in nestedDictionary.Keys) 
  {
      foreach(int targetValue in nestedDictionary[key1].Values) 
      {
          if(targetValue &gt; 5) { continue; }
  
          if(targetValue &gt; highestTargetInConstraint)
          {
              highestTargetInConstraint = targetValue;
          }
      }
  }
  </code></pre>
  
  <p>This is the most appropriate way to loop through a flat dictionary as mentioned in <a href="https://stackoverflow.com/questions/141088/what-is-the-best-way-to-iterate-over-a-dictionary/59053661#59053661">this post</a>. I can't imagine to get faster than this, but maybe you can refute.</p>
  
  <p>Now I'm wondering if there is a syntactically better way to loop through a nested dictionary by using a custom iterator. Useful hints and pointers to relevant documents are appreciated.</p>