title: Why covariance and contravariance do not support value type
body: <p><code>IEnumerable&lt;T&gt;</code> is <em>co-variant</em> but it does not support value type, just only reference type. The below simple code is compiled successfully:</p>
  
  <pre><code>IEnumerable&lt;string&gt; strList = new List&lt;string&gt;();
  IEnumerable&lt;object&gt; objList = strList;
  </code></pre>
  
  <p>But changing from <code>string</code> to <code>int</code> will get compiled error:</p>
  
  <pre><code>IEnumerable&lt;int&gt; intList = new List&lt;int&gt;();
  IEnumerable&lt;object&gt; objList = intList;
  </code></pre>
  
  <p>The reason is explained in <a href="http://msdn.microsoft.com/en-us/library/dd799517.aspx#InterfaceCovariantTypeParameters" rel="noreferrer">MSDN</a>:</p>
  
  <blockquote>
    <p>Variance applies only to reference types; if you specify a value type for a variant type parameter, that type parameter is invariant for the resulting constructed type.</p>
  </blockquote>
  
  <p>I have searched and found that some questions mentioned the reason is <em>boxing between value type and reference type</em>. But it does not still clear up my mind much why boxing is the reason?</p>
  
  <p>Could someone please give a simple and detailed explanation why covariance and contravariance do not support value type and how <em>boxing</em> affects this?</p>