title: Why can't I cast `this` to a generic type?
body: <p>I'm having an issue wrapping my head around why neither of the following snippets compile.</p>
  <p>Visual Studio flags the first one with:</p>
  <blockquote>
  <p>Cannot convert type 'SomeType' to 'T'</p>
  <p>Cast is redundant.</p>
  </blockquote>
  <pre class="lang-cs prettyprint-override"><code>using System;
  
  public class SomeClass {
      public T Coerce&lt;T&gt;() {
          if (typeof(T) == typeof(SomeClass))
              return (T)this; // &lt;- Error CS0030
          else throw new InvalidCastException();
      }
  }
  </code></pre>
  <p>Removing the &quot;redundant&quot; cast, however, just changes the error to:</p>
  <blockquote>
  <p>Cannot implicitly convert type 'SomeOtherClass' to 'T'</p>
  </blockquote>
  <pre class="lang-cs prettyprint-override"><code>using System;
  
  public class SomeOtherClass {
      public T Coerce&lt;T&gt;() {
          if (typeof(T) == typeof(SomeOtherClass))
              return this; // &lt;- Error CS0029
          else throw new InvalidCastException();
      }
  }
  </code></pre>