Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // DrawingObject Object do = new DrawingObject();
            Circle circle = new Circle();
            circle.Name = "My Circle";
            circle.Draw();

            Square square = new Square();
            square.Name = "My Square";
            square.Draw();

            // create a List collection for Drawing Objects
            List<DrawingObject> drawingObjects = new List<DrawingObject>();
            // add few objects to collection
            drawingObjects.Add(new Circle());
            drawingObjects.Add(new Square());
            drawingObjects.Add(new Circle());
            drawingObjects.Add(new Square());
            drawingObjects.Add(new Circle());
            drawingObjects.Add(new Square());
            drawingObjects.Add(new Circle());
            drawingObjects.Add(new Square());

            // loop collection and draw objects
            Console.WriteLine("Drawing objects in a List:");
            foreach(DrawingObject drawingObject in drawingObjects)
            {
                drawingObject.Draw();
            }


            Console.WriteLine("Square: " + square.Name);
            Console.ReadLine();

        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Shape c = new Circle();
            c.setColor("blue");
            Shape s = new Square();
            s.setColor("red");

            List<Shape> shapes = new List<Shape>();
            shapes.Add(c);
            shapes.Add(s);

            foreach (Shape q in shapes)
            {
                Console.WriteLine(q.getColor());
                Console.WriteLine(q.calculateArea());
            }
            Console.ReadKey();
        }