Object.MemberwiseClone Method

Creates a shallow copy of the current instance (object) of the Object class.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

Syntax

[MethodImplAttribute]
protected Object MemberwiseClone ()

Return Value

A shallow copy of the current object.

Remarks

The MemberwiseClone method cannot be overridden, and it is accessible only through this class or a derived class. Use a class that implements the ICloneable interface if a deep or shallow copy of an object needs to be publicly exposed to users.

A shallow copy creates a new instance of the same type as the original object, and then it copies the nonstatic fields of the original object. If the field is a value type, a bit-by-bit copy of the field is performed. If the field is a reference type, the reference is copied but the referenced object is not, with the result that the reference in the original object and the reference in the clone point to the same object. By contrast, a deep copy of an object duplicates everything that is directly or indirectly referenced by the fields in the object.

Version Information

Available in the .NET Micro Framework versions 2.0, 2.5, 3.0, 4.0, 4.1, and 4.2.

See Also

Reference

Object Class
Object Members
System Namespace