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

            var f1 = new Fruit();
            f1.Name = "Apple";
            f1.Weight = 2.00;
            produce.Add(f1);

            var f2 = new Fruit();
            f1.Name = "banada";
            f1.Weight = 4.6;
            produce.Add(f2);

            produce.Add(new Vegetable());

            ((Vegetable)produce[2]).Name="Carrot";
            ((Vegetable)produce[2]).Weight = 4.5;

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

            foreach (var item in produce)
            {
                Console.WriteLine(item);
            }

        }
예제 #2
0
파일: Program.cs 프로젝트: niuniuliu/CSharp
        static void Main(string[] args)
        {
            var produce = new List<object>();

            var f1 = new Fruit();
            produce.Add(f1);

            var f2 = new Fruit();
            produce.Add(f2);

            produce.Add(new Vegetable());

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

            foreach (var item in produce)
            {
                Console.WriteLine(item);
            }

        }
예제 #3
0
        static void Main(string[] args)
        {
            var produce = new List<object>();

            var f1 = new Fruit("Apple", 8.5, 3);
            produce.Add(f1);

            var f2 = new Fruit("Banana", 4.5, 7);
            produce.Add(f2);

            produce.Add(new Vegetable("Carrot", 4.1, 16));
            //((Vegetable)produce[2]).Name = "Carrot";
            //((Vegetable)produce[2]).Weight = 4.1;
            //((Vegetable)produce[2]).Quantity = 16;

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

            foreach (var item in produce)
            {
                Console.WriteLine(item);
            }

        }