由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问一下deep copy和shallow copy的问题(C#)
相关主题
被Facebook的面试的一道题目难倒了问道面试题
老问题了,网上竟然找不到答案做道有序数组元素求最大和题?
找2个sorted array中的第K小的元素,有O(lgn)方法吗?Amazon 面试题
两个Sorted Array,找K smallest element问一个问题(4)
Find the intersection of two sorted arrays【扩展】两个数组找duplicated有什么好办法
请教一下external sorting的问题问道amazon 面试题
a question攒RP,ZocDoc 面经
新鲜C3 energy面经出一道我发明的题,难度算简单吧。
相关话题的讨论汇总
话题: array话题: copy话题: array1话题: int话题: shallow
进入JobHunting版参与讨论
1 (共1页)
b*******y
发帖数: 1240
1
以下程序
copyto和clone都执行shallow copy,但是为什么程序里面反映不出来,谢谢
int[] array = new int[] { 1, 2, 3, 4, 5, 6 };
//create shallow copy by CopyTo
//You have to instantiate your new array first
int[] array2 = new int[myarray.Length];
//but then you can specify how many members of original array yo
u would like to copy
array.CopyTo(array2, 0);
//create shallow copy by Clone
int[] array1;
//here you don't need to instantiate array,
//but all elements of the original array will be copied
array1 = array.Clone() as int[];
//if not sure that we create a shalow copy lets test it
array[0] = 0;
Console.WriteLine(array[0]);// print 0
Console.WriteLine(array1[0]);//print 1
Console.WriteLine(array2[0]);//print 1
Console.WriteLine(array == array1); // print false
b*******y
发帖数: 1240
2
有人知道么
谢谢

yo

【在 b*******y 的大作中提到】
: 以下程序
: copyto和clone都执行shallow copy,但是为什么程序里面反映不出来,谢谢
: int[] array = new int[] { 1, 2, 3, 4, 5, 6 };
: //create shallow copy by CopyTo
: //You have to instantiate your new array first
: int[] array2 = new int[myarray.Length];
: //but then you can specify how many members of original array yo
: u would like to copy
: array.CopyTo(array2, 0);
: //create shallow copy by Clone

1 (共1页)
进入JobHunting版参与讨论
相关主题
出一道我发明的题,难度算简单吧。Find the intersection of two sorted arrays【扩展】
顶风作案,贡献一道最近onsite的原题请教一下external sorting的问题
unsorted int array怎么找到第一个大于0,并且不在此array的数a question
Clone() vs new新鲜C3 energy面经
被Facebook的面试的一道题目难倒了问道面试题
老问题了,网上竟然找不到答案做道有序数组元素求最大和题?
找2个sorted array中的第K小的元素,有O(lgn)方法吗?Amazon 面试题
两个Sorted Array,找K smallest element问一个问题(4)
相关话题的讨论汇总
话题: array话题: copy话题: array1话题: int话题: shallow