一开始,先对C#深拷贝与浅拷贝知识做个简单的总结. 无论是浅拷贝与深拷贝,C#都将源对象中的所有字段复制到新的对象中.不过,对于值类型字段,引用类型字段以及字符串类型字段的处理,两种拷贝方式存在一定的区别(见下表). 下面给出完整的演示代码. using System; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; namespa
在.net framework中,提供了ICloneable接口来对对象进行克隆.当然,你也可以不去实现ICloneable接口而直接自己定义一个Clone()方法,当然,还是推荐实现ICloneable接口. 具体实现方法 using UnityEngine; using System.Collections; using System; using System.IO; using System.Runtime.Serialization; using System.Runtime.Seri