title: generic with new() constraint, can't take string as type
body: <p>I have written a generic class</p>
  
  <pre><code> class MyClass : MyClass&lt;string&gt; { } //this line is in error
  
   class MyClass&lt;OutputBaseType&gt; : MyClass&lt;OutputBaseType, List&lt;OutputBaseType&gt;&gt;
       where OutputBaseType : new() //this new constraint is needed
   {}
   class MyClass&lt;OutputBaseType,OutputType&gt; 
      where OutputType : ICollection&lt;OutputBaseType&gt;, new()
      where OutputBaseType : new()
   {
       public void Method(OutputBaseType z)
       {
           if (z!=null) { ... }
       }
   ...
   }
  </code></pre>
  
  <p>Because string has no default constructor the first line will now work. If I remove this line and modify clients to explicitly define string, then it does not work for the same reason.</p>
  
  <p>If I remove  <code>where OutputBaseType : new()</code>  and the other <code>new()</code> then it works with <code>OutputBaseType</code> of <code>string</code> but not with <code>OutputType</code> of <code>dictionary&lt;...&gt;</code>. This is because <code>KeyValuePair&lt;&gt;</code> used by dictionary is a <code>struct</code> not a <code>class</code>, so can not be <code>null</code>. (I don't like null usually but need it here)</p>
  
  <p>Is there a way to get this to work?</p>
  
  <hr>
  
  <p>Amendments:</p>
  
  <p>I have removed new constraint on OutputBaseType.
  Then replaced assigning of null and assigning with default construction, with default(OutputBaseType)</p>
  
  <p>This looks promising but I now have an error in the condition expression on line</p>
  
  <pre><code>OutputBaseType outputItem = ...;
  if (outputItem != default(OutputBaseType)) { _Output.Add(outputItem); }
  </code></pre>
  
  <p>The error is:</p>
  
  <pre><code>Operator '!=' cannot be applied to operands of type 'OutputBaseType' and 'OutputBaseType'   
  </code></pre>