Exemple #1
0
        public void CallingInterfaceMethods()
        {
            // New up an instance of an Ifruit
            IFruit fruit = new Orange();    //calling just Ifruit props , not banana or orange
                                            // we can change new Banana to Orange or grape and get new output for everything
            string output = fruit.Peel();

            Console.WriteLine(output);

            Console.WriteLine($"The {fruit.Name} is peeled: " + fruit.Peeled);

            var fruits = new Orange();  // but from here I can call orange sqeeze method, because "var" not Ifruit.

            fruits.Squeeze();
        }
Exemple #2
0
        public void InterfacesInCollections()
        {
            var orange     = new Orange(); //could put Orange in place of var but did that so this is dry code
            var fruitSalad = new List <IFruit>();

            fruitSalad.Add(orange);
            fruitSalad.Add(new Banana());
            fruitSalad.Add(new Grape());

            foreach (var fruit in fruitSalad)
            {
                Console.WriteLine(fruit.Name);
                Console.WriteLine(fruit.Peel());
            }
            Console.WriteLine(orange.Squeeze()); //can't go inside of foreach loop because fruit in the foreach loop is of type IFruit
        }
Exemple #3
0
        public void InterfacesInCollections()
        {
            var orange = new Orange();

            var fruitSalad = new List <IFruit>();

            fruitSalad.Add(orange);
            fruitSalad.Add(new Banana());
            fruitSalad.Add(new Grape());

            foreach (var fruit in fruitSalad)
            {
                Console.WriteLine(fruit.Name);
                Console.WriteLine(fruit.Peel());
            }
            Console.WriteLine(orange.Squeeze());  //this can be called directly because it is only in orange class.  can't be part of the foreach loop
        }
Exemple #4
0
        public void OrangeTest()
        {
            Orange orange   = new Orange(true);
            Orange unOrange = new Orange(false);

            Console.WriteLine(orange.Peel());
            Console.WriteLine(unOrange.Peel());

            string SmallerNum(string n1, string n2)
            {
                int result = String.Compare(n1, n2);

                return(result <= 0 ? n1 : n2);
            }

            Console.WriteLine(SmallerNum("21", "56"));
        }
        public void InterfacesInCollections()
        {
            var orange = new Orange();

            var fruitSalad = new List <IFruit>();

            fruitSalad.Add(orange);
            fruitSalad.Add(new Banana());
            fruitSalad.Add(new Grape());

            foreach (var fruit in fruitSalad)
            {
                Console.WriteLine(fruit.Name);
                Console.WriteLine(fruit.Peel());
            }
            Console.WriteLine(orange.Squeeze());
        }
Exemple #6
0
        public void TestMethod1()
        {
            Orange orange         = new Orange(true);
            Orange unpeeledOrange = new Orange(false);

            Console.WriteLine(orange.IsPeeled);
            Console.WriteLine(unpeeledOrange.IsPeeled);

            Console.WriteLine(orange.Peel());
            Console.WriteLine(unpeeledOrange.Peel());

            Banana banana = new Banana();

            List <IFruit> fruitBasket = new List <IFruit>();

            fruitBasket.Add(banana);
            fruitBasket.Add(orange);
        }
Exemple #7
0
        public void FruitTest()
        {
            Orange foo            = new Orange(true);
            Orange unpeeledOrange = new Orange(false);

            Console.WriteLine(foo.IsPeeled);
            Console.WriteLine(unpeeledOrange.IsPeeled);

            Console.WriteLine(foo.Peel());
            Console.WriteLine(unpeeledOrange.Peel());

            Banana banana = new Banana();

            List <IFruit> fruitBasket = new List <IFruit>();

            fruitBasket.Add(banana);
            fruitBasket.Add(foo);
            fruitBasket.ToArray();
        }
Exemple #8
0
        public void FruitTest()
        {
            Orange orange         = new Orange(true);
            Orange unpeeledOrange = new Orange(false);

            Console.WriteLine(orange.IsPeeled);
            Console.WriteLine(unpeeledOrange.IsPeeled);

            Console.WriteLine(orange.Peel());
            Console.WriteLine(unpeeledOrange.Peel());

            Banana jake = new Banana();

            List <IFruit> fruitBasket = new List <IFruit>();

            fruitBasket.Add(jake);
            fruitBasket.Add(orange);
            fruitBasket.Add(unpeeledOrange);
        }