日斋
日新月异

 public static void CopyIntArray()
        {
            int[] one = { 3, 4 };
            int[] clone = (int[])one.Clone();
            clone[0] = 33;
            Console.WriteLine(one[0]);
        }

        public static void CopyPersonArray()
        {
            Person[] personArr1 = {
                        new Person("John", "Lennon"),
                        new Person("Paul", "McCartney")
                      };
            //Clone()方法 创建浅复制副本
            Person[] personArr2 = (Person[])personArr1.Clone();

            personArr2[0].LastName = "test";
            Console.WriteLine(personArr1[0].LastName);

            Person[] personArr3 = new Person[2];
            //Array.Copy()方法创建浅复制副本。
            personArr1.CopyTo(personArr3, 0);
            personArr3[0].LastName = "abc";
            Console.WriteLine(personArr1[0].LastName);


        }

posted on 2010-10-09 21:32  李承隆  阅读(127)  评论(0编辑  收藏  举报