日常啪啪啪代码的时候,常常遇到浅复制与深复制的问题,下面就自己经验写写,有问题请留言! 例如我有一个简单的类: class People { public int _age; public string _name; public People(int Age,string Name) { _age = Age; _name = Name; } } 常见的赋值语句,如: People Mike = ,"Mike"); People Mike2 = Mike; 这是浅复制,共享同一块内存
参考copy链接:http://blog.csdn.net/bigconvience/article/details/25025561 在看原型模式,发现要用到clone这个方法,以前和朋友聊过,没怎么看过,刚好要用,就看看了. 源码解释: /** * Creates and returns a copy of this object. The precise meaning * of "copy" may depend on the class of the object. The