I would like to know if is there any way to copy one object to the other, without changing their memory locations, in example below.
class PersonData
{
public string PersonName;
public int age;
public PersonData(string name, int age)
{
this.age = age;
PersonName = name;
}
}
class Program
{
static void Main(string[] args)
{
object person1 = new PersonData("FirstPerson",20);
object person2 = new PersonData("secondPerson",30);
person1 = person2;
}
}
person1 will start pointing to the memory location of person2. what I would like to do just copy the VALUES of person2 at the memory location of person1. is there any method other than
person1.age = person2.age;
person1.name = person2.name;
because I don't know the fields of the object beforehand.
thank you in advance.