![]() |
VOOZH | about |
Object.MemberwiseClone Method is used to create a shallow copy or make clone of the current Object. Shallow copy is a bit-wise copy of an object. In this case, a new object is created and that object has an exact copy of the existing object. Basically, this method copies the non-static fields of the current object to the new object.
Syntax:
protected object MemberwiseClone ();
Returns: This method returns a Object, which is the shallow copy of existing Object. Example 1:
Value: 3 cloned value: 3 Value: 6 cloned value: 6
Example 2:
For Old values Original : Name = ABC, Surname = XYZ, Age 26 Cloned : Name = ABC, Surname = XYZ, Age 26 After assigning new values Original : Name = LMN, Surname = QRS, Age 13 Cloned : Name = ABC, Surname = XYZ, Age 26
Reference: