title: Help with C# generics error - "The type 'T' must be a non-nullable value type"
body: <p>I'm new to C# and don't understand why the following code doesn't work.</p>
  
  <pre><code>public static Nullable&lt;T&gt; CoalesceMax&lt;T&gt;(Nullable&lt;T&gt; a, Nullable&lt;T&gt; b) where T : IComparable
  {
      if (a.HasValue &amp;&amp; b.HasValue)
          return a.Value.CompareTo(b.Value) &lt; 0 ? b : a;
      else if (a.HasValue)
          return a;
      else
          return b;
  }
  
  // Sample usage:
  public DateTime? CalculateDate(DataRow row)
  {
      DateTime? result = null;
      if (!(row["EXPIRATION_DATE"] is DBNull))
          result = DateTime.Parse((string)row["EXPIRATION_DATE"]);
      if (!(row["SHIPPING_DATE"] is DBNull))
          result = CoalesceMax(
              result
              DateTime.Parse((string)row["SHIPPING_DATE"]).AddYears(1));
      // etc.
      return result;
  }
  </code></pre>
  
  <p>It gives the following error during compilation: </p>
  
  <blockquote>The type 'T' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable&lt;T&gt;'</blockquote>