title: Sorting from earliest to latest date
body: <p>How to loop every month's first date. </p>
  
  <pre><code>public struct stat{
  public DateTime date;
  }
  </code></pre>
  
  <p>I have a <code>List&lt;stat&gt;</code> that have a date property. I want to get the lowest and newest one by sorting. the first element is older and last is newer one.</p>
  
  <p>I can easily got the first and second by order by.</p>
  
  <p>What I want is get 1st date of every month in the between of both first (oldest ) and newest.</p>
  
  <p>string ret = "";</p>
  
  <pre><code>    List&lt;DateTime&gt; dates = new List&lt;DateTime&gt;();
  
      int breaker = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
  
      stats = stats.OrderBy(x =&gt; x.Date).ToList();
      DateTime old = stats.First().Date;
      DateTime @new = stats.Last().Date;
  
      int diffdays = @new.Subtract(old).Days;
  
      DateTime loopd = DateTime.Now;
  
      for (int i = 0; i &lt; diffdays; i = i + breaker)
      {
          loopd = loopd.AddDays(-breaker);
          dates.Add(loopd);
          if (loopd &lt; old)
              Console.WriteLine("date" + old);
      }
  
      for (int j = 0; j &lt; dates.Count; j++)
      {
          if (j == 0)
          {
              DateTime ld= dates[0];
              stats.SelectMany(x =&gt; x.Date &lt; @new &amp;&amp; x.Date &gt; dates[j]);
          }
      }
  </code></pre>