static void Main(string[] args) { Cleaner simpleCleaner = new Cleaner(); //Boxing occurs here to box the Cleaner into a more generic object type. TryCauseMayhem(simpleCleaner); TryCleanup(simpleCleaner); MayhemCauser simpleMayhem = new MayhemCauser(); TryCauseMayhem(simpleMayhem); TryCleanup(simpleMayhem); IClean catHatClean = new CatHat(); ICauseMahem catHatMayhem = catHatClean as ICauseMahem; //This works because cat hat implements both interfaces. TryCauseMayhem(catHatClean); //These will both work because of the multiple interface implementation. TryCleanup(catHatMayhem); ThingOne thingOne = new ThingOne(); TryCauseMayhem(thingOne); TryCleanup(thingOne); ThingTwo thingTwo = new ThingTwo(); TryCauseMayhem(thingTwo); TryCleanup(thingTwo); Console.ReadKey(); }
static void Main(string[] args) { Cleaner simpleCleaner = new Cleaner(); //Boxing occurs here to box the Cleaner into a more generic object type. TryCauseMayhem(simpleCleaner); TryCleanup(simpleCleaner); MayhemCauser simpleMayhem = new MayhemCauser(); TryCauseMayhem(simpleMayhem); TryCleanup(simpleMayhem); IClean catHatClean = new CatHat(); ICauseMahem catHatMayhem = catHatClean as ICauseMahem;//This works because cat hat implements both interfaces. TryCauseMayhem(catHatClean);//These will both work because of the multiple interface implementation. TryCleanup(catHatMayhem); ThingOne thingOne = new ThingOne(); TryCauseMayhem(thingOne); TryCleanup(thingOne); ThingTwo thingTwo = new ThingTwo(); TryCauseMayhem(thingTwo); TryCleanup(thingTwo); Console.ReadKey(); }