Transfer of references between objects: Deep copy and shortest copy in. NET, and. net copy
1. ScenarioFirst, the scenario is like this. There is a Person class, which has a property of the Car type. Used to express a person-driven car. The Car class describes attributes such as the automobile platter. This is the basic scenario.2. Shallow copyPerson p1 = new Person (); p1.DaiBu = new Car () {Brand = "Audi A6"}; // you can specify p1 as the proxy tool. Person p2 = new Person (); // in this case, we say that a shortest copy has occurred. It is actually a reference transfer between common objects. P2.DaiBu = p1.DaiBu;3. Deep copy// What is deep copy? Person p2 = new Person (); // This is a deep copy! P2.DaiBu = new Car () {Brand = p1.DaiBu. Brand };
4. Demo Diagram// What is the difference between deep copy and light copy? We use a picture to describe it!