Hi,
This works because probably the Dog class is derived from the Animal class. Making the Dog an Animal.
public class Animal{}
public class Dog : Animal {}
This means that in a collection of Animal, we can always put a Dog.
All dogs are animals, but not all animals are dogs.
Now, if we were to introduce a Cat
public class Cat : Animal {}
We can also insert this Cat into a collection of Animal. Because it is an Animal.
We will not be able though to put just any Animal in a collection of Dog, because that would mean that we could just put a Cat in there. That's why we would need to cast an object to a Dog to do so.
var dog = new Dog();
var cat = new Cat();
var animals = new List<Animal>();
animals.Add(dog);
animals.Add(cat);
var dogs = new List<Dog>();
dogs.Add(dog);
dogs.Add(cat);
HTH Christiaan