Example #1
0
        public void OutMethod()
        {
            //IIndex<Rectangle> rectangles = RectangleCollection.GetRectangles();
            //IIndex<Shape> shapes = rectangles;  //因为 限定了返回为Rectangle类型 所以赋值给Shape类型没有问题(简写如下)
            IIndex <Shape> shapes = RectangleCollection.GetRectangles();

            for (int i = 0; i < shapes.Count; ++i)
            {
                Console.WriteLine(shapes[i]);
            }
        }
Example #2
0
 public static RectangleCollection GetRectangles()
 {
     return(coll ?? (coll = new RectangleCollection()));
 }