static void Main(string[] args) { Console.WriteLine("Hello World!"); var b = new Banana(); var s = new Strawberry(); var m = new Mango(); var c = new IceCubes(); var p = new CellPhone(); Console.WriteLine(b.Blend()); Console.WriteLine(s.Blend()); Console.WriteLine(m.Blend()); List <IBlendable> fruits = new List <IBlendable>() { b, s, m, c, p }; foreach (var fruit in fruits) { Console.WriteLine(fruit.GetType()); Console.WriteLine(fruit.Blend()); } }
static void Main(string[] args) { List <IBlendable> blendabels = new List <IBlendable>(); blendabels.Add(new Strawberry()); blendabels.Add(new Banana()); blendabels.Add(new CellPhone()); blendabels.Add(new IceCubes()); for (int i = 0; i < 10; i++) { blendabels.Add(new Mango()); } Banana b = new Banana(); Console.WriteLine(b.Blend()); blendabels.Add(b); string mess = ""; foreach (IBlendable blendable in blendabels) { mess += blendable.Blend(); } Console.WriteLine(mess); }
static void Main(string[] args) { List <IBlendable> blendables = new List <IBlendable>(); blendables.Add(new Strawberry()); blendables.Add(new Banana()); blendables.Add(new CellPhone()); blendables.Add(new IceCubes()); //Add 10 Mangos for (int i = 0; i < 10; i++) { blendables.Add(new Mango()); } Banana b = new Banana(); Console.WriteLine(b.Blend()); blendables.Add(b); // Print all items in list foreach (IBlendable blendable in blendables) { Console.WriteLine(blendable.Blend()); } }
static void Main(string[] args) { var b = new Banana(); var m = new Mango(); var s = new Strawberry(); var c = new IceCubes(); Console.WriteLine(b.Blend()); Console.WriteLine(m.Blend()); Console.WriteLine(s.Blend()); List <IBlendable> fruits = new List <IBlendable>() { b, m, s, c }; foreach (var fruit in fruits) { Console.WriteLine(fruit.Blend()); } foreach (dynamic fruit in fruits) { Console.WriteLine(fruit.Blend()); } }
static void Main(string[] args) { List <IBlendable> blendables = new List <IBlendable>(); blendables.Add(new Strawberry()); blendables.Add(new Banana()); blendables.Add(new CellPhone()); blendables.Add(new IceCubes()); for (int i = 0; i < 10; i++) { blendables.Add(new Mango()); } Strawberry strawberry = new Strawberry(); Banana b = new Banana(); Console.WriteLine(b.Blend()); blendables.Add(b); string mess = ""; ///whatever you are are i wnat you to use what you are /// foreach(dynamic i in blendables) //{ // mess += i.Blend(); /// } ///the right way would be to override the methode foreach (IBlendable i in blendables) { mess += i.Blend(); } Console.WriteLine(mess); }
static void Main(string[] args) { List <IBlendable> blendables = new List <IBlendable>(); blendables.Add(new Strawberry()); blendables.Add(new Banana()); blendables.Add(new CellPhone()); blendables.Add(new IceCubes()); for (int i = 0; i < 10; i++) { blendables.Add(new Mango()); } //Strawberry strawberry = new Strawberry(); Banana b = new Banana(); Console.WriteLine(b.Blend()); blendables.Add(b); string mess = ""; foreach (IBlendable blendable in blendables) //dynamic keyword - "whatever you are, you what you are" { mess += blendable.Blend(); } Console.WriteLine(mess); }
static void Main(string[] args) { List <IBlendable> blendables = new List <IBlendable>(); blendables.Add(new Strawberry()); blendables.Add(new Banana()); blendables.Add(new CellPhone()); blendables.Add(new IceCubes()); for (int i = 0; i < 10; i++) { blendables.Add(new Mango()); } Banana b = new Banana(); Console.WriteLine(b.Blend()); string mess = ""; // dynamic keyword let's the object "control" what they are foreach (IBlendable blendable in blendables) { mess += blendable.Blend(); } Console.WriteLine(mess); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var b = new Banana(); var m = new Mango(); var s = new Strawberry(); var c = new IceCubes(); Console.WriteLine(b.Blend()); Console.WriteLine(m.Blend()); Console.WriteLine(s.Blend()); List <IBlendable> fruits = new List <IBlendable> { b, m, s, c }; foreach (IBlendable fruit in fruits) { Console.WriteLine(fruit.Blend()); } }
static void Main(string[] args) { //Console.WriteLine("Hello World!"); var b = new Banana(); var m = new Mango(); var s = new Strawberry(); var c = new IceCubes(); Console.WriteLine(b.Blend()); Console.WriteLine(m.Blend()); Console.WriteLine(s.Blend()); List <IBlendable> list = new List <IBlendable>() { b, m, s, c }; foreach (dynamic blend in list) { Console.WriteLine(blend.Blend()); } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var b = new Banana(); var m = new Mango(); var s = new Strawberry(); var c = new IceCubes(); Console.Write(b.Blend() + "\n\n"); Console.Write(m.Blend() + "\n\n"); Console.Write(s.Blend() + "\n\n"); List <Iblendable> snax = new List <Iblendable>() { b, m, s, c }; foreach (Iblendable f in snax) { Console.Write(f.Blend() + "\n\n"); } }