Creates a shallow copy of the current Object.
[Visual Basic] Protected Function MemberwiseClone() As Object [C#] protected object MemberwiseClone(); [C++] protected: Object* MemberwiseClone(); [JScript] protected function MemberwiseClone() : Object;
A shallow copy of the current Object.
A shallow copy of an Object is a copy of the Object only. If the Object contains references to other objects, the shallow copy will not create copies of the referred objects, but will refer to the original objects instead. On the other hand, a deep copy of an object creates a copy of the object and a copy of everything directly or indirectly referenced by that object.
For example, if X is an Object with references to the objects A and B, and the object A also has a reference to an object M, a shallow copy of X is an object Y, which also has references to objects A and B. On the other hand, a deep copy of X is an object Y with direct references to objects C and D, and an indirect reference to object N, where C is a copy of A, D is a copy of B, and N is a copy of M.
This method cannot be overridden; a subclass should implement the ICloneable interface if a shallow copy is not appropriate. This method is protected so that only subclasses can call it on themselves.
Object Class | Object Members | System Namespace | ICloneable