Exemple #1
0
 static void HaveADrink(HotDrink h)
 {
     h.AddMilk();
     h.Drink();
     if (h is ICup)
     {
         ICup cupOfDrink = h as ICup;
         //ICup cupOfDrink =(ICup)h;
         cupOfDrink.Wash();
     }
 }
Exemple #2
0
        static void UseHotdrinks(HotDrink hotDrink)
        {
            hotDrink.AddMilk();
            hotDrink.Drink();

            // Book Solution
            // Because not all HotDrinks have to be ICups, check
            if (hotDrink is ICup)
            {
                ((ICup)hotDrink).Wash();
            }
        }