To perform Shallow copy in C# , you can use the this.MemberwiseClone() method.
How to perform Shallow Copy in C# ?
Below is a sample code snippet that contains a method ShallowCopy to make a copy of the object.
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public List<Languages> LanguagesKnown { get; set; }
public Employee ShallowCopy()
{
return (Employee)this.MemberwiseClone();
}
}
1 Comment