title: Get previous element of a dictionary
body: <p>for several reason I have <code>Dictionary&lt;string, string&gt;</code> and I'm checking it in a foreach loop. I have no way (at least I didn't find a smart solution) to replace it either with a list, array or a <code>Dictionary&lt;int, string&gt;</code>. The dictionary is composed of server name, status of the package (2 strings).</p>
  
  <p>I'm trying to get the previous element in the foreach cycle, in order to compare it with the current element.</p>
  
  <p>My code:</p>
  
  <pre><code>foreach (KeyValuePair &lt;string,string&gt; pair in packageDistribution) { 
       if (pair.Value == "package distribution complete") { 
            // print pair.Key + " - Installed"; 
       } else {
           // print pair.Key + " - " + pair.Value
       } 
       if (i%3==0) "OR" (i== packageDistribution.count) { 
         // print the values \n 
       } 
  }
  </code></pre>
  
  <p>I need to group them 3 by 3 to save space, but my problem is I would like to print to new line even if the current element differs from the previous one:  </p>
  
  <pre><code>pair.Key.substring(0,4) != previousElement.substring(0,4)
  </code></pre>
  
  <p>My servers look like <code>NLDN1234, NLDN1235, NSTM2345, NSTM9874</code> and I would like to group them depending on their names.</p>
  
  <p>Does anyone have a smart suggestion?</p>