title: Loop through current years month to next year month in c#
body: <p>I am facing a problem, logic written in my program is below</p>
  
  <pre><code>while (lastDate.Month &lt; DateTime.Today.Month - 1)//
    {
      lastDate= lastDate.AddMonths(1);
      list.Add(lastDate);
    }
  </code></pre>
  
  <p>This code is failing when lastDate month is Dec and i am executing this code in Jan or Feb of new year because 12 would never be greater then 1 0r 2.</p>
  
  <p>I need to write a logic where my loop could traverse through Nov, Dec, Jan , Feb and so on.</p>
  
  <p>I have written below code which is working however i am not getting clue to exit, loop should exit when difference between lastDate and todays date is 2 months.</p>
  
  <pre><code>if (lastDate.Month &gt; DateTime.Today.Month &amp;&amp; lastDate.Year &lt; DateTime.Today.Year)
   {
    while (lastDate.Year &lt;= DateTime.Today.Year)
     {
       lastDate= lastDate.AddMonths(1);
       list.Add(lastDate);
  
     }
  </code></pre>
  
  <p>}</p>
  
  <p>Please help me in this</p>