title: Unable to cast base class to derived class
body: <p>I have base class as Animal and child class as Dog</p>
  
  <p>Here is the code:</p>
  
  <pre><code>class Animal
  {
      public int Legs { get; set; }
  
      public string Name  { get; set; }
  }
  
  class Dog : Animal
  {
      public int noOfTail { get; set; }
  }
  </code></pre>
  
  <p>In My Main Method when I execute below I get the exception:</p>
  
  <pre><code>   static void Main(string[] args)
      {
          Animal a = new Animal();
          Dog d = new Dog();
          d = (Dog)a;
      }
  </code></pre>
  
  <p>but when I first cast my derived class to parent I don't get any exception, and that is why I am confused, can somebody explain reason behind it.</p>
  
  <pre><code>   static void Main(string[] args)
      {
          Animal a = new Animal();
          Dog d = new Dog();
          a = d;
          d = (Dog)a;
      }
  </code></pre>