title: C# Why an explicit cast isn't needed here?
body: <p>How does this code work without an explicit cast?</p>
  
  <pre><code>static void Main()
  {
      IList&lt;Dog&gt; dogs = new List&lt;Dog&gt;();
      IEnumerable&lt;Animal&gt; animals = dogs;
  }
  </code></pre>
  
  <p>I am talking about this line:</p>
  
  <pre><code>IEnumerable&lt;animal&gt; animals = dogs;
  </code></pre>
  
  <p>You can see here that I am able to pass the variable dogs without an explicit cast. But how is this possible? Why did the compiler allow me do this? Shouldn't I first do the cast like this:</p>
  
  <pre><code>IEnumerable&lt;Animal&gt; animals = (List&lt;Dog&gt;) dogs;
  </code></pre>
  
  <p>The code will work with the explicit cast and without the explicit cast but I cannot understand why it allowed me to assign dogs to the animals reference variable without an explicit cast.</p>