static void Main(string[] args) { Circle figure = new Circle(30, 50, 60); Circle clonedFigure = figure.Clone() as Circle; //---------Example of deep copy figure.GetInfo(); clonedFigure.GetInfo(); figure.Radius = 1000; figure.GetInfo(); clonedFigure.GetInfo(); //---------Example of deep copy //---------Example of shalow copy //---------But class doesn't contain referense type Rectangle rectangle = new Rectangle(20, 40); Rectangle clonedRectangle = rectangle.Clone() as Rectangle; rectangle.GetInfo(); clonedRectangle.GetInfo(); Console.ReadKey(); }
static void Main(string[] args) { Circle c = new Circle(new Point(5, 5), 50.5); Console.WriteLine(c); DoStuffWithCircle((Circle)c.Clone()); Console.WriteLine(c); Rectangle r = new Rectangle(new Point(5, 5), new Point(10, 5), new Point(5, 10), new Point(10, 10)); Console.WriteLine(r); DoStuffWithRectangle((Rectangle)r.Clone()); Console.WriteLine(r); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// ShapeHolder s1 = new ShapeHolder(); s1.AddShape(c); s1.AddShape(r); Console.WriteLine(s1); DoStuffWithList((ShapeHolder)s1.Clone(), c); Console.WriteLine(s1); }
static void Main() { //значимый тип Console.WriteLine("Значимый тип:"); Rectangle first = new Rectangle(5, 10); Console.WriteLine(first); Rectangle second = first.Clone() as Rectangle; Console.WriteLine(second); first.Height = 50; Console.WriteLine(first); Console.WriteLine(second); //ссылочный тип Console.WriteLine("\nСсылочный тип:"); ICloneableRectangle cloneableRectangle = new CloneableRectangle(new Size(10, 20)); Console.WriteLine(cloneableRectangle); ICloneableRectangle clonedCloneableRectangle = cloneableRectangle.Clone(); Console.WriteLine(clonedCloneableRectangle); cloneableRectangle.Size = new Size(100, 100); Console.WriteLine(cloneableRectangle); Console.WriteLine(clonedCloneableRectangle); Console.ReadKey(); }
static void Main(string[] args) { Circle circle = new Circle(); circle.X = 10; circle.Y = 10; circle.Radius = 20; Console.WriteLine("Circle instance"); Console.WriteLine(circle); Console.WriteLine("Cloning circle"); Circle clonedCircle = (Circle)circle.Clone(); Console.WriteLine("Cloned circle"); Console.WriteLine(clonedCircle); Rectangle rectangle = new Rectangle(); rectangle.Width = 10; rectangle.Height = 20; Console.WriteLine("Rectangle instance"); Console.WriteLine(rectangle); Console.WriteLine("Cloning rectangle"); Rectangle clonedRectangle = (Rectangle)rectangle.Clone(); Console.WriteLine("Cloned rectangle"); Console.WriteLine(clonedRectangle); }
static void Main(string[] args) { // Circle Circle shape1 = new Circle("1"); shape1.Print(); Circle shape1_copy = shape1.Clone() as Circle; shape1_copy.Print(); // Square Square shape2 = new Square("2"); shape2.Print(); Square shape2_copy = shape2.Clone() as Square; shape2_copy.Print(); // Rectangle Rectangle shape3 = new Rectangle("3"); shape3.Print(); Rectangle shape3_copy = shape3.Clone() as Rectangle; shape3_copy.Print(); Console.WriteLine(); // CacheManager //ShapeManager shapeManager = new ShapeManager(); //Circle c_circle = new Circle("a1"); //Square c_square = new Square("a2"); //Rectangle c_rectangle = new Rectangle("a3"); //shapeManager["Circle"] = c_circle; //shapeManager["Square"] = c_square; //shapeManager["Rectangle"] = c_rectangle; //Circle cloned_c_circle = shapeManager["Circle"].Clone() as Circle; //Square cloned_c_square = shapeManager["Square"].Clone() as Square; //Rectangle cloned_c_rectangle = shapeManager["Rectangle"].Clone() as Rectangle; //c_circle.Print(); //cloned_c_circle.Print(); //c_square.Print(); //cloned_c_square.Print(); //c_rectangle.Print(); //cloned_c_rectangle.Print(); Console.ReadLine(); }
static void Main(string[] args) { var rectangle = new Rectangle(40, 50); var clonedRectangle = (Rectangle)rectangle.Clone(); Console.WriteLine($"Rectangle size: width - {rectangle.Width}, height - {rectangle.Height}"); Console.WriteLine($"Cloned rectangle size: width - {clonedRectangle.Width}, height - {clonedRectangle.Height}"); Console.ReadKey(); }
static void Main(string[] args) { IFigure figure = new Rectangle(30, 40); IFigure clonedFigure = figure.Clone(); figure.GetInfo(); clonedFigure.GetInfo(); figure = new Circle(30); clonedFigure = figure.Clone(); figure.GetInfo(); clonedFigure.GetInfo(); }
static void Main(string[] args) { IFigure figure = new Rectangle(30, 40); IFigure clonedFigure = figure.Clone(); figure.GetInfo(); clonedFigure.GetInfo(); Circle figure1 = new Circle(5, 4, 2); Circle clonedFigure1 = figure1.Clone() as Circle; figure1.GetInfo(); clonedFigure1.GetInfo(); Console.ReadKey(); }
static void Main(string[] args) { IFigure figure = new Rectangle(12, 12); IFigure figureClone = figure.Clone(); figure.GetInfo(); figureClone.GetInfo(); figure = new Circle(30); figureClone = figure.Clone(); figure.GetInfo(); figureClone.GetInfo(); Console.ReadLine(); }
static void Main(string[] args) { IFigure figure = new Rectangle(10, 20); IFigure clonedFigure = figure.Clone(); figure.GetInfo(); clonedFigure.GetInfo(); figure = new Circle(15); clonedFigure = figure.Clone(); figure.GetInfo(); clonedFigure.GetInfo(); figure = new Triangle(10, 20, 25); clonedFigure = figure.Clone(); figure.GetInfo(); clonedFigure.GetInfo(); }
static void Main(string[] args) { Shape circle = new Circle(0, 0, 5); Shape rectangle = new Rectangle(5, 0, 2, 3); Shape clonedCircle = circle.Clone(); Shape clonedRectanle = rectangle.Clone(); Console.WriteLine(circle == clonedCircle); circle.Show(); clonedCircle.Show(); Console.WriteLine(rectangle == clonedRectanle); rectangle.Show(); clonedRectanle.Show(); }
private static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Green; Console.Title = "Prototype"; IFigure figure = new Rectangle(30, 40); var clonedFigure = figure.Clone(); figure.GetInfo(); clonedFigure.GetInfo(); figure = new Circle(30); clonedFigure = figure.Clone(); figure.GetInfo(); clonedFigure.GetInfo(); Console.ReadKey(); }
private void PrototypeStart(object sender, RoutedEventArgs e) { IFigure figure = new Prototype.Rectangle(30, 40); IFigure clonedFigure = figure.Clone(); MessageBox.Show(figure.GetInfo()); MessageBox.Show(clonedFigure.GetInfo()); figure = new Circle(30); clonedFigure = figure.Clone(); MessageBox.Show(figure.GetInfo()); MessageBox.Show(clonedFigure.GetInfo()); figure = new Circle(15); MessageBox.Show(figure.GetInfo()); Circle deepClonedFigure = figure.DeepCopy() as Circle; MessageBox.Show(deepClonedFigure.GetInfo()); }
static void Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; IFigure figure = new Rectangle(10, 20); IFigure clonedFigure = figure.Clone(); figure.GetInfo(); clonedFigure.GetInfo(); figure = new Circle(15); clonedFigure = figure.Clone(); figure.GetInfo(); clonedFigure.GetInfo(); figure = new Triangle(3, 4, 5); clonedFigure = figure.Clone(); figure.GetInfo(); clonedFigure.GetInfo(); Console.Read(); }
static void Main(string[] args) { IFigure figure = new Rectangle(30, 40); IFigure clonedFigure = figure.Clone(); ((Rectangle)clonedFigure).Point.X = 1; ((Rectangle)clonedFigure).Point.Y = 1; figure.GetInfo(); clonedFigure.GetInfo(); Console.WriteLine(new string('-', 52)); figure = new Rectangle(30, 40); clonedFigure = ((Rectangle)figure).DeepCopy() as IFigure; ((Rectangle)clonedFigure).Point.X = 1; ((Rectangle)clonedFigure).Point.Y = 1; figure.GetInfo(); clonedFigure.GetInfo(); Console.Read(); }