point/cloneable-vs-copy-constructor/Client.cs - Polymorphic Cloning of Points. | Lecture 8 - slide 32 : 41 Program 3 |
using System; using System.Drawing; using System.Collections.Generic; public class Application{ public static void Main(){ Point p1 = new Point(1.1, 2.2), p2 = new Point(3.3, 4.4); ColorPoint cp1 = new ColorPoint(5.5, 6.6, Color.Red), cp2 = new ColorPoint(7.7, 8.8, Color.Blue); List<Point> pointList = new List<Point>(), clonedPointList = new List<Point>(); pointList.Add(p1); pointList.Add(cp1); pointList.Add(p2); pointList.Add(cp2); // Clone the points in pointList and add them to clonedPointList: foreach(Point p in pointList){ clonedPointList.Add((Point)(p.Clone())); } foreach(Point p in clonedPointList) Console.WriteLine("{0}", p); } }