BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 System.Runtime.InteropServices.ComVisible(true)

The interface enables you to provide a customized implementation that creates a copy of an existing object. The interface contains one member, the method, which is intended to provide cloning support beyond that supplied by . For more information about cloning, deep versus shallow copies, and examples, see the method.

Supports cloning, which creates a new instance of a class with the same value as an existing instance.

- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Object

  The following example shows an implementation of that uses the method to create a copy of the current instance.

  `using System; class MyClass :ICloneable { public int myField; public MyClass() { myField = 0; } public MyClass(int value) { myField = value; } public object Clone() { return this.MemberwiseClone(); } } public class TestMyClass { public static void Main() { MyClass my1 = new MyClass(44); MyClass my2 = (MyClass) my1.Clone(); Console.WriteLine("my1 {0} my2 {1}",my1.myField, my2.myField); my2.myField = 22; Console.WriteLine("my1 {0} my2 {1}",my1.myField, my2.myField); } }`

  The output is

  my1 44 my2 44

  my1 44 my2 22

  The resulting clone must be of the same type as, or compatible with, the original instance.

  An implementation of can perform either a deep copy or a shallow copy. In a deep copy, all objects are duplicated; in a shallow copy, only the top-level objects are duplicated and the lower levels contain references. Because callers of cannot depend on the method performing a predictable cloning operation, we recommend that not be implemented in public APIs.

  See for more information on cloning, deep versus shallow copies, and examples.

  Creates a new object that is a copy of the current instance.

  A new object that is a copy of this instance.

  0
0