title: Why do C# out generic type parameters violate covariance?
body: <p>I'm unclear as to why the following code snippet isn't covarient?</p>
  
  <pre><code>  public interface IResourceColl&lt;out T&gt; : IEnumerable&lt;T&gt; where T : IResource {
  
      int Count { get; }
  
      T this[int index] { get; }
  
      bool TryGetValue( string SUID, out T obj ); // Error here?
      }
  </code></pre>
  
  <blockquote>
    <p>Error 1   Invalid variance: The type parameter 'T' must be invariantly
    valid on 'IResourceColl.TryGetValue(string, out T)'. 'T' is
    covariant.</p>
  </blockquote>
  
  <p>My interface only uses the template parameter in output positions.  I could easily refactor this code to something like</p>
  
  <pre><code>  public interface IResourceColl&lt;out T&gt; : IEnumerable&lt;T&gt; where T : class, IResource {
  
      int Count { get; }
  
      T this[int index] { get; }
  
      T TryGetValue( string SUID ); // return null if not found
      }
  </code></pre>
  
  <p>but I'm trying to understand if my original code actually violates covariance or if this is a compiler or .NET limitation of covariance.</p>