c# constructor copy object code example
Example 1: c# copy an object
class TestClass
{
public TestClass Copy()
{
return MemberwiseClone();
}
}
Example 2: copy constructor c#
class Person
{
private string firstName;
private string lastName;
private byte age;
//Copy Constructor
public Person(Person obj)
{
this.firstName = obj.firstName;
this.lastName = obj.lastName;
this.age = obj.age;
}
}