title: How to check if a list is sorted consecutively?
body: <p>I need to re-order a list <strong>consecutively</strong> if it is already not. Can anyone suggest a way to check it so that I can write an extension method to call like this?</p>
  
  <pre><code>var cglist = collectionGroups.OrderBy(x =&gt; x.Sequence).ToList();
  
  if (cglist.IsConsecutive)
  {
     for (int i = 0; i &lt; cglist.Count(); i++)
     {
        //sorting logic...
      } 
   }
  </code></pre>
  
  <p><code>x.Sequence</code> is not an incremented property in the entity and has duplicates and missing values. This data is fed to my context from an outer source which I have no control of. So I need to use it in a reordering method and make it adjacent</p>
  
  <p>I could find the closest solution from this answer <a href="https://stackoverflow.com/a/37442325/3275061">here</a> which does not really seem to be checking adjacency.</p>