title: How to get the item before current and after current in a dictionary with Linq / C#?
body: <p>I have a dictionary of projects and if I select a project then I will give an option previous and next. I have added a code example but I hope there is a better / faster way to do this e.g. for 500 projects. </p>
  
  <p>Is there maybe a LINQ option or something?</p>
  
  <p>I have checked Enumerator but it only has a <code>moveNext</code> method and can't set the current.</p>
  
  <p><strong>Quick example:</strong></p>
  
  <p><code>projects</code> is a <code>Dictionary</code>.</p>
  
  <p><code>project</code> is a <code>KeyValuePair</code> that exists in the <code>Dictionary</code>.</p>
  
  <pre><code>var match = false;
  var save = new KeyValuePair&lt;ExtendedProjectLightPlan, Page&gt;();
  var before = new KeyValuePair&lt;ExtendedProjectLightPlan, Page&gt;();
  var after = new KeyValuePair&lt;ExtendedProjectLightPlan, Page&gt;();
  foreach (var p in projects)
  {
      before = save;
      save = p;
  
      if (match)
      {
          after = p;
          break;
      }
  
      if (p.Key.Id == project.Key.Id)
      {
          match = true;
      }                
  }
  </code></pre>