Exemplo n.º 1
0
        static void Main(string[] args)
        {
            List <Product> cart = new List <Product>();

            Milk milk = new Milk();

            milk.fatContent    = 1;
            milk.ProductNumber = 123;
            milk.stockStatus   = 10;

            cart.Add(milk);

            Nocco nocco = new Nocco();

            nocco.flavor        = "Cola";
            nocco.ProductNumber = 234;
            nocco.stockStatus   = 14;

            cart.Add(nocco);

            Coffe coffe = new Coffe();

            coffe.roastyness    = "Medium roast";
            coffe.ProductNumber = 321;
            coffe.stockStatus   = 0;


            cart.Add(coffe);

            foreach (Product product in cart)
            {
                if (product.GetType() == typeof(Milk))
                {
                    Console.WriteLine(((Milk)product).fatContent);
                }

                else if (product.GetType() == typeof(Coffe))
                {
                    Console.WriteLine(((Coffe)product).roastyness);
                }

                else if (product.GetType() == typeof(Nocco))
                {
                    Console.WriteLine(((Nocco)product).flavor);
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            List <Product> cart = new List <Product>();

            Milk milk = new Milk();

            milk.FatContent    = 1;
            milk.ProductNumber = 123;
            milk.StockStatus   = 10;

            cart.Add(milk);

            EnergyDrink nocco = new EnergyDrink();

            nocco.Flavor        = "Cola";
            nocco.ProductNumber = 456;
            nocco.StockStatus   = 14;

            cart.Add(nocco);

            Coffee coffee = new Coffee();

            coffee.RoastLevel    = "Vienna";
            coffee.ProductNumber = 789;
            coffee.StockStatus   = 12;

            cart.Add(coffee);

            foreach (var product in cart)
            {
                if (product.GetType() == typeof(Milk))
                {
                    Console.WriteLine(((Milk)product).FatContent);
                }
                else if (product.GetType() == typeof(EnergyDrink))
                {
                    Console.WriteLine(((EnergyDrink)product).Flavor);
                }
                else if (product.GetType() == typeof(Coffee))
                {
                    Console.WriteLine(((Coffee)product).RoastLevel);
                }
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            List <Product> cart = new List <Product>();

            Milk milk = new Milk();

            milk.FatContent    = 1;
            milk.ProductNumber = 123;
            milk.StockStatus   = 10;

            Nocco nocco = new Nocco();

            nocco.Flavor        = "Cola";
            nocco.ProductNumber = 234;
            nocco.StockStatus   = 14;

            Coffee coffee = new Coffee();

            coffee.Rostyness     = "Dark AF";
            coffee.ProductNumber = 345;
            coffee.StockStatus   = 0;

            cart.Add(coffee);
            cart.Add(milk);
            cart.Add(nocco);

            foreach (var product in cart)
            {
                if (product.GetType() == typeof(Milk))
                {
                    Console.WriteLine(((Milk)product).GetType().Name);
                }
                else if (product.GetType() == typeof(Coffee))
                {
                    Console.WriteLine(((Coffee)product));
                }
                else if (product.GetType() == typeof(Nocco))
                {
                    Console.WriteLine(((Nocco)product));
                }
            }
        }