VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/object-memberwiseclone-method-in-c-sharp-with-examples/

⇱ Object.MemberwiseClone Method in C# with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Object.MemberwiseClone Method in C# with Examples

Last Updated : 11 Jul, 2025

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.

  • If a field is a reference type, then the only reference is copied not the referred object. So here, the cloned object and the original object will refer to the same object.
  • If the field is value type then the bit-by-bit copy of the field will be performed.

Syntax:

protected object MemberwiseClone ();

Returns: This method returns a Object, which is the shallow copy of existing Object. Example 1: 

Output:
Value: 3
cloned value: 3

Value: 6
cloned value: 6

Example 2: 

Output:
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:

Comment
Article Tags:

Explore