title: Can you satisfy a generic constraint with an implicit conversion?
body: <p>Given these types:</p>
  
  <pre><code>class A { }
  class B
  {
      public static implicit operator A(B me)
      {
          return new A();
      }
  }
  
  class Test&lt;T&gt; where T : A { }
  </code></pre>
  
  <p>I tried</p>
  
  <pre><code>var b = new Test&lt;B&gt;();
  </code></pre>
  
  <p>And expected it to fail, which it did. But the error message is</p>
  
  <blockquote>
    <p>The type 'B' cannot be used as type parameter 'T' in the generic type or method 'Test'. There is no implicit reference conversion from 'B' to 'A'.</p>
  </blockquote>
  
  <p><strike>But there <em>is</em> an implicit reference conversion from B to A. Is this just a strange message?</strike> There is <em>not</em> an implicit reference conversion as Adam Robinson's answer shows. The message is correct.</p>
  
  <p>Note that <a href="http://msdn.microsoft.com/en-us/library/d5x73970.aspx" rel="nofollow">MSDN says:</a></p>
  
  <blockquote>
    <p>where T : (base class name) - The type argument must be or derive from the specified base class.</p>
  </blockquote>
  
  <p>Which explains why it is not allowed since <code>B</code> does not derive from <code>A</code></p>