예제 #1
0
        static void Main(string[] arg)
        {
            var produce = new List <Produce>();

            produce.Add(new Fruit("Apple", 8.5, 3));
            produce.Add(new Fruit("Bananna", 4.5, 7));
            produce.Add(new Vegetable("Carrot", 4.1, 16));

            Console.WriteLine("There are {0} items", produce.Count);

            foreach (var item in produce)
            {
                Console.WriteLine(item + ", " + ProduceUtility.GetItemWeight(item) + "oz");
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Polymorhism!");

            var produce = new List <Produce>();

            produce.Add(new Fruit("Apple", 8.5, 3));
            produce.Add(new Fruit("Banana", 4.5, 7));
            produce.Add(new Vegetable("Carrot", 4.1, 16));

            Console.WriteLine("There are " + produce.Count + " items");

            foreach (var item in produce)
            {
                Console.WriteLine(item + ", total weight: " +
                                  ProduceUtility.GetItemWeight(item) + "oz");
            }

            Console.WriteLine("Total weight: " +
                              ProduceUtility.GetTotalWeight(produce) + "oz");
        }