日期:2014-05-18  浏览次数:20709 次

关于 Array.Copy
Array.Copy是浅拷贝,
      string[]   str   =   new   string[]   {   "hello ",   "world "   };
                        string[]   str2   =   new   string[2];
                        Array.Copy(str,   str2,   str.Length);
                        str2[1]   =   "how   are   you ";
                        Console.WriteLine( "after   Copy   &   Change:   {0} ",   str[1]);//显示world  

从上面代码结果似乎string不是需动态分配内存的类型???还是Array.Copy对string类型特别处理??   或者其他原因...

------解决方案--------------------
字符串是托管对象,不是普通的数值

就象你说你的,这是浅拷贝,第一个数组存有指向 "hello "和 "world " 2个字符串的指针(引用),第二个数组在拷贝后也指向了这2个字符串,但随后,你改变了第二个数组里第二个对象的指针,但并没有改变第一个数组里的指针