title: Why does C# (4.0) not allow co- and contravariance in generic class types?
body: <p>What is the <strong>real</strong> reason for that limitation? Is it just work that had to be done? Is it conceptually hard? Is it impossible?</p>
  
  <p>Sure, one couldn't use the type parameters in fields, because they are allways read-write. But that can't be the answer, can it?</p>
  
  <p>The reason for this question is that I'm writing an article on variance support in C# 4, and I feel that I should explain why it is restricted to delegates and interfaces. Just to inverse the onus of proof.</p>
  
  <p><strong>Update:</strong>
  Eric asked about an example.</p>
  
  <p>What about this (don't know if that makes sense, yet :-))</p>
  
  <pre><code>public class Lookup&lt;out T&gt; where T : Animal {
    public T Find(string name) {
      Animal a = _cache.FindAnimalByName(name);
      return a as T;
    }
  }
  
  var findReptiles = new Lookup&lt;Reptile&gt;();
  Lookup&lt;Animal&gt; findAnimals = findReptiles;
  </code></pre>
  
  <p>The reason for having that in one class could be the cache that is held in the class itself. And please don't name your different type pets the same!</p>
  
  <p>BTW, this brings me to <a href="https://stackoverflow.com/questions/2541659/what-about-optional-generic-type-parameters-in-c-5-0">optional type parameters in C# 5.0</a>  :-)</p>
  
  <p><strong>Update 2:</strong> I'm not claiming the CLR and C# should allow this. Just trying to understand what led to that it doesnt. </p>