Добрый день! изучаю программирование на C# вот возник вопрос
| Код | using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace ShapeVirtual { abstract class Shape { protected int xPos; protected int yPos;
public Shape(int x, int y) { xPos = x; yPos = y; }
abstract public void Draw(int x, int y); } class Point : Shape { public Point(int x, int y) : base(x,y) { }
public override void Draw(int x, int y) { Console.WriteLine("Рисование точки в ({0}, {1})", x, y); xPos=x; yPos=y; } } class Rectangle : Shape { int widht; int height;
public Rectangle(int x, int y, int w, int h) : base(x, y) { widht = w; height = h; }
public override void Draw(int x, int y) { Console.WriteLine("Рисование прямоугольника в ({0}, {1})", x, y); xPos = x; yPos = y; } } class ShapeVirtualApp { static void Main(string[] args) { Shape[] allShapes = new Shape[4]; allShapes[0] = new Point(1, 5); allShapes[3] = new Rectangle(2, 3, 1, 5); allShapes[2] = new Rectangle(1, 2, 3, 4); allShapes[1] = new Point(31, 4);
foreach (Shape currentShape in allShapes) currentShape.Draw(1, 0);
Console.ReadLine(); } } }
|
Вобщем тут все четыре фигуры "рисуются" в одной точке с координатами (1,0), как можно изменить цикл таким образом, чтобы каждая фигура была нарисована на своем месте? |