title: Check if a date range is within a date range
body: <p>I have the following class:</p>
  
  <pre><code>public class Membership
  {
      public DateTime StartDate { get; set; }
      public DateTime? EndDate { get; set; } // If null then it lasts forever
  }
  </code></pre>
  
  <p>I need to make sure when adding to the following list that the new item doesn't overlap the dates from existing item:</p>
  
  <pre><code>var membership = new List&lt;Membership&gt;
  {
      new Membership { StartDate = DateTime.UtcNow.AddDays(-10), EndDate = DateTime.UtcNow.AddDays(-5) },
      new Membership { StartDate = DateTime.UtcNow.AddDays(-5), EndDate = null }
  };
  </code></pre>
  
  <p>For example doing:</p>
  
  <pre><code>var newItem = new Membership { StartDate = DateTime.UtcNow.AddDays(-15), EndDate = DateTime.UtcNow.AddDays(-10) }; // Allowed
  
  var newItem2 = new Membership { StartDate = DateTime.UtcNow.AddDays(-15), EndDate = null }; // Not Allowed
  
  if (AllowededToAdd(newItem))
      membership.Add(newItem);
  
  if (AllowededToAdd(newItem2))
      membership.Add(newItem2);
  </code></pre>
  
  <p>I thought this would be simple but so far my attempts have all been wrong and i'm starting to confuse myself and was hoping someone had done something similar they could share.  Thanks</p>