Ejemplo n.º 1
0
        public void InterfacesInMethods()
        {
            var grape  = new Grape();
            var output = GetFruitName(grape);

            Console.WriteLine(output);
            Assert.IsTrue(output.Contains("This fruit is called Grape"));
        }
Ejemplo n.º 2
0
        public void InterfacesInMethods()
        {
            var grape  = new Grape();
            var output = GetFruitName(grape);//used the above method

            Console.WriteLine(output);
            Assert.IsTrue(output.Contains("This fruit is called Grape"));// make sure it is exactly same as part one above
        }
Ejemplo n.º 3
0
        public void TypeOfInstance()
        {
            var tomato     = new Grape();
            var fruitSalad = new List <IFruit>
            {
                new Orange(),
                new Grape(),
                new Banana(true),
                new Orange(),
                new Banana(),
                tomato,
            };

            Console.WriteLine("Is the banana peeled?");
            foreach (var fruit in fruitSalad)
            {
                if (fruit is Banana)
                {
                    var banana = (Banana)fruit;
                    if (banana.Peeled)
                    {
                        Console.WriteLine("Yes the banana is peeled!");
                        banana.Slice();
                    }
                    else
                    {
                        Console.WriteLine("Sorry bud, this banana isn't peeled");
                    }
                }
                else if (fruit.GetType() == typeof(Grape))
                {
                    Console.WriteLine("Congrats on the Grape");
                }
                else
                {
                    Console.WriteLine("What a nice orange you have...too bad its not a tangerine :(");
                }
            }
        }
Ejemplo n.º 4
0
        public void TypeOfInstance()
        {
            var tomato     = new Grape();      /// just added it since we needed more fruit for example
            var fruitSalad = new List <IFruit> ///using {} instead of () since we have to add list belwo
            {
                new Orange(),
                new Grape(),
                new Banana(true),
                new Orange(),
                new Banana(),
                tomato,
            };

            Console.WriteLine("Is the banana peeled");
            foreach (var fruit in fruitSalad) /// it is going to go through each item in fruitsalad
            {
                if (fruit is Banana banana)   /// it is casing IFruit to Banana if it mathces//this line is called pattern matching
                {
                    if (banana.Peeled)
                    {
                        Console.WriteLine("Yes the banana is peeled!");
                    }
                    else
                    {
                        Console.WriteLine("Sorry bud, this banana isn't peeled");
                    }
                }
                else if (fruit.GetType() == typeof(Grape))// this is to include Grape
                {
                    Console.WriteLine("Congrats on the Grape");
                }
                else//to have orange included
                {
                    Console.WriteLine("What a nice orange you have... to bad its not a tangerine:(");
                }
            }
        }