using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { //值类型成功复制(复制所有的值) int[] t = { 1, 12, 3 }; int[] a = (int[])t.Clone(); a[0] = 100; Console.WriteLine(t[0]); Console.ReadKey(); //引用类型复制复制失败(只复制了引用) Person[] p = new Person[] { new Person { Name = "ass" }, new Person { Name = "鸣人" } }; Person[] pp = (Person[])p.Clone(); pp[0].Name = "zhangsan"; Console.WriteLine(p[0].Name); Console.ReadKey(); //如果要创建引用类型的数组,就必须迭代数组并创建新的对象 } } }
本文出自 “程序猿的家” 博客,请务必保留此出处http://962410314.blog.51cto.com/7563109/1440647
原文地址:http://962410314.blog.51cto.com/7563109/1440647