title: Is creating a C# generic method that accepts (nullable) value type and reference type possible?
body: <p>I want to create a simple method that accepts both <em>value type</em> and <em>reference type</em> parameters, i.e. int is value, and string is reference.</p>
  <p>So this is what I start with:</p>
  <pre><code>public bool AreBothNotNull&lt;T&gt;(T? p1, T? p2)
  {
      return (p1.HasValue &amp;&amp; p2.HasValue);
  }
  </code></pre>
  <p>So I want to be able to use it like this:</p>
  <pre><code>var r1 = AreBothNotNull&lt;int&gt;(3, 4); // will be true
  var r2 = AreBothNotNull&lt;int&gt;(3, null); // will be false
  var r3 = AreBothNotNull&lt;string&gt;(&quot;three&quot;, &quot;four&quot;); // will be true
  var r4 = AreBothNotNull&lt;string&gt;(null, &quot;four&quot;); // will be false
  </code></pre>
  <p>But the first issue I encounter is</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'
  </blockquote>
  <p>To proceed I add a struct constraint to my method</p>
  <pre><code>public bool AreBothNotNull&lt;T&gt;(T? p1, T? p2) where T : struct
  </code></pre>
  <p>But now the method won't accept the string based calls, and gives me this error:</p>
  <blockquote>
  The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method.
  </blockquote>
  <p>Is this possible? Or why are we prevented from doing this?</p>