using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Csharp
{
public abstract class GeometricShape
{
public abstract void Draw();
}
public class Rectangle : GeometricShape
{
override public void Draw()
{
Console.WriteLine("Rectangle.Draw");
}
}
public class Circle : GeometricShape
{
override public void Draw()
{
Console.WriteLine("Circle.Draw");
}
}
public class Drawing
{
private ArrayList shapes;
public Drawing()
{
shapes = new ArrayList();
}
public int Count
{
get
{
return shapes.Count;
}
}
public GeometricShape this[int index]
{
get
{
return (GeometricShape)shapes[index];
}
}
public void Add(GeometricShape shape)
{
shapes.Add(shape);
}
}
class Program
{
static void Main(string[] args)
{
Rectangle rectangle = new Rectangle();
Circle circle = new Circle();
Drawing drawing = new Drawing();
drawing.Add(rectangle);
drawing.Add(circle);
for (int i = 0; i < drawing.Count; ++i)
{
GeometricShape shape = drawing[i];
shape.Draw();
}
}
}
}
C#索引器
最新推荐文章于 2024-04-15 07:40:40 发布