static void HaveADrink(HotDrink h) { h.AddMilk(); h.Drink(); if (h is ICup) { ICup cupOfDrink = h as ICup; //ICup cupOfDrink =(ICup)h; cupOfDrink.Wash(); } }
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(); } }