private static void ReferenceTypeAssignment() { Console.WriteLine("Assigning reference types\n"); var personClass1 = new PersonClass(1, "name1", OccupationEnum.Student); var personClass2 = personClass1; Console.WriteLine(personClass1); // automatically calls .ToString(). The method is defined in System.Object and overridden in PersonClass Console.WriteLine(personClass2); // Change personClass1.Name and _age and print again. personClass2.Name and _age have changed. personClass1.Name = "NewUserName"; personClass1.SetAge(22); Console.WriteLine("\n=> Changed personClass1.Name and personClass1._age\n"); Console.WriteLine(personClass1); Console.WriteLine(personClass2); }
//Copy constructor - https://msdn.microsoft.com/en-us/library/ms173116.aspx public PersonClass(PersonClass previousPerson) : this(previousPerson.GetAge(), previousPerson.Name, previousPerson.Occupation) { Console.WriteLine("Copy Constructor"); }