title: DateTime.AddDays or new DateTime
body: <p>I'm creating a list of a month's worth of dates.  I'm wondering what will be more efficient</p>
  
  <pre><code>List&lt;DateTime&gt; GetDates(DateTime StartDay) {
    List&lt;DateTime&gt; dates = new List&lt;DateTime&gt;();
    int TotalDays=StartDay.AddMonths(1).AddDays(-1).Day;
    for (int i=1; i&lt;TotalDays; i++) {
      dates.Add(new DateTime(StartDay.Year, StartDay.Month, i));
    }
    return dates;
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>List&lt;DateTime&gt; GetDates(DateTime StartDay) {
    List&lt;DateTime&gt; dates = new List&lt;DateTime&gt;();
    DateTime NextMonth = StartDay.AddMonths(1);
    for (DateTime curr=StartDay; !curr.Equals(NextMonth); curr=curr.AddDays(1)) {
      dates.Add(curr);
    }
    return dates;
  }
  </code></pre>
  
  <p>basically, is new DateTime() or DateTime.addDays more efficient.  </p>
  
  <p>UPDATE:</p>
  
  <pre><code>static void Main(string[] args) {
    System.Diagnostics.Stopwatch sw=new System.Diagnostics.Stopwatch();
    long t1, t2, total;
    List&lt;DateTime&gt; l;
    DateTime begin = DateTime.Now;
    total = 0L;
    for (int i=0; i&lt;10; i++) {
      sw.Start();
      l = GetDates(begin);
      sw.Stop();
  
  
      sw.Stop();
      t1 = sw.ElapsedTicks;
      sw.Reset();
      sw.Start();
  
      l = GetDates2(begin);
      sw.Stop();
      t2=sw.ElapsedTicks;
      total +=  t1- t2;
  
      Console.WriteLine("Test {0} : {1} {2} : {3}", i,t1,t2, t1- t2);
    }
    Console.WriteLine("Total: {0}", total);
  
    Console.WriteLine("\n\nDone");
    Console.ReadLine();
  }
  
  static List&lt;DateTime&gt; GetDates(DateTime StartDay) {
    List&lt;DateTime&gt; dates = new List&lt;DateTime&gt;();
    int TotalDays=StartDay.AddMonths(10000).AddDays(-1).Day;
    for (int i=1; i&lt;TotalDays; i++) {
      dates.Add(new DateTime(StartDay.Year, StartDay.Month, i));
    }
    return dates;
  }
  
  
  static List&lt;DateTime&gt; GetDates2(DateTime StartDay) {
    List&lt;DateTime&gt; dates = new List&lt;DateTime&gt;();
    DateTime NextMonth = StartDay.AddMonths(10000);
    for (DateTime curr=StartDay; !curr.Equals(NextMonth); curr=curr.AddDays(1)) {
      dates.Add(curr);
    }
    return dates;
  }
  </code></pre>
  
  <pre>
  Test 0 : 2203229 63086205 : -60882976
  Test 1 : 63126483 102969090 : -39842607
  Test 2 : 102991588 93487982 : 9503606
  Test 3 : 93510942 69439034 : 24071908
  Test 4 : 69465137 70660555 : -1195418
  Test 5 : 70695702 68224849 : 2470853
  Test 6 : 68248593 63555492 : 4693101
  Test 7 : 63578536 65086357 : -1507821
  Test 8 : 65108190 64035573 : 1072617
  Test 9 : 64066128 64933449 : -867321
  Total: -62484058
  
  Done
  </pre>
  
  <p>results are consistently negative... way negative, so, looks like the constructor and integer test is the more efficient method.</p>