예제 #1
0
 static void Main(string[] args)
 {
     IAnimalCollection <IAnimal> animalCollection = GetDogCollection();
     //animalCollection.AddAnimal(new Cat()); //Would get a compiler error because this method no longer exists.
 }
예제 #2
0
 public AnimalService(IAnimalCollection collection)
 {
     _collection = collection;
 }
    static void Main(string[] args)
    {
        IAnimalCollection <IAnimal> animalCollection = GetDogCollection();

        animalCollection.AddAnimal(new Cat());     //We just added a cat to a collection of dogs.
    }
 static void Main(string[] args)
 {
     IAnimalCollection <IAnimal> animalCollection = GetDogCollection();
     //animalCollection.AddAnimal(new Cat()); //Would get a compiler error if we tried to add a cat to the collection
 }