C# generics - why is an explicit cast needed to from a concrete type back to T?
<p>This has been bothering me for a while. I'm having a little trouble understanding why explicit casts are needed in the following code:</p>

<pre><code>public static class CastStrangeness
{
    public class A
    {
    }

    public class B
        : A
    {
    }

    public static void Foo&lt;T&gt;(T item)
        where T : A
    {
        // Works.
        A fromTypeParameter = item;

        // Does not compile without an explicit cast.
        T fromConcreteType = (T)fromTypeParameter;

        // Does not compile without an explicit cast.
        Foo&lt;T&gt;((T)fromTypeParameter);
    }

    public static void Bar(A item)
    {
        // Compiles.
        Foo&lt;A&gt;(item);
    }
}
</code></pre>

<p>It seems to me that T is guaranteed to be an A, so surely the compiler could infer that any instance of A is guaranteed to be assignable to T? Otherwise, I wouldn't be able to pass an A or a B into Foo(). So what am I missing?</p>

<p>PS. I've tried searching for endless permutations of keywords on this, but every result seems to wind up referring to covariance and contravariance WRT generic interfaces :)</p>
