title: generics covariance and explicit casting
body: <p>If I try and do:</p>
  
  <pre><code>IDictionary&lt;uint, IEnumerable&lt;string&gt;&gt; dict = new Dictionary&lt;uint, List&lt;string&gt;&gt;();
  </code></pre>
  
  <p>I get the error:</p>
  
  <blockquote>
    <p>error CS0266: Cannot implicitly convert type
    'System.Collections.Generic.Dictionary>'
    to
    'System.Collections.Generic.IDictionary>'.
    An explicit conversion exists (are you missing a cast?)</p>
  </blockquote>
  
  <p>If I add the cast:</p>
  
  <pre><code>IDictionary&lt;uint, IEnumerable&lt;string&gt;&gt; dict = (IDictionary&lt;uint, IEnumerable&lt;string&gt;&gt;)new Dictionary&lt;uint, List&lt;string&gt;&gt;();
  </code></pre>
  
  <p>Then it compiles.</p>
  
  <p>Why do I need the explicit cast? And is it safe? I thought the whole point on covariance was the ability to implicitly cast safely?</p>
  
  <p><strong>EDIT:</strong> 
  C# prevents unrelated casting eg</p>
  
  <pre><code>string s = (string)0L;
  </code></pre>
  
  <blockquote>
    <p>error CS0030: Cannot convert type 'long' to 'string'</p>
  </blockquote>
  
  <p>It does allow explicit downcasting of related types when you know that the object is actually a subclass:</p>
  
  <pre><code>Animal animal = new Cat();
  Cat cat = (Cat)animal;
  </code></pre>
  
  <p>I am confused why the compiler is offering, and allowing me to explicitly cast to an IDictionary with incompatible types.</p>