public void InterfacesInCollectons() { var orange = new Orange(); // used var becaus it is an variable and newed it var fruitSalad = new List <IFruit> //take out() and add {} to make and add the list for the List { new Banana(), new Grape(), orange// just because oranged has been newed already so don't have to put new infront }; foreach (var fruit in fruitSalad) { Console.WriteLine(fruit.Name);//fruit.-will only share the IFruit quility not squeeze Console.WriteLine(fruit.Peel()); Assert.IsInstanceOfType(fruit, typeof(IFruit)); } Console.WriteLine(orange.squeeze());// used it here since squeeze wasn't availabe above since it is differnt all other IFruits }
public void InterfacesInCollections() { var orange = new Orange(); var fruitSalad = new List <IFruit> { new Banana(), new Grape(), orange }; foreach (var fruit in fruitSalad) { Console.WriteLine(fruit.Name); Console.WriteLine(fruit.Peel()); Assert.IsInstanceOfType(fruit, typeof(IFruit)); } Console.WriteLine(orange.Squeeze()); }