日期:2014-05-17 浏览次数:21339 次
Triangle tri = new Triangle { Width = 3, Length = 4 };
Rectangular rec = new Rectangular { X = 1, Y = 3 };
Circle cir = new Circle { Radius = 4 };
List<object> list = new List<object>();//这不是List发挥作用的地方,如果非要这样还是使用ArrayList
list.Add(tri);
list.Add(rec);
list.Add(cir);
foreach (object item in list)
{
if (item is Triangle)
{
int width = ((Triangle)item).Width;
int length = ((Triangle)item).Length;
}
else if (item is Rectangular)
{
int x = ((Rectangular)item).X;
int y = ((Rectangular)item).Y;
}
else if (item is Circle)
{
int radius = ((Circle)item).Radius;
}
}