123
1 2 3 4 5 6 7 8 9 |
static IPointy FindFirstPointyShape(Shape[] shapes) { foreach (var s in shapes) { if (s is IPointy) { return s as IPointy; } } return null; } |
In Main
1 2 3 |
Shape[] shapes = { new Triangle("Triangle"), new Hexagon("Hexagon"), new Circle("Circle") }; IPointy firstPointyItem = FindFirstPointyShape(shapes); Console.WriteLine("Item has {0} points", firstPointyItem.Points); |