Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array.Copy(source2,2,target,3,2);
- source.CopyTo(target,0);
- public static void Copy(Array sourceArray, long sourceIndex, Array destinationArray, long destinationIndex, long length);
- public void CopyTo(Array array, int index);
- Array.Copy(source,2,target,2,2);
- source.CopyTo(target,0);
- Array.Copy(source,2,ref target,2,2);//передача по ссылке
- source.CopyTo(ref target,0);//передача по ссылке
- void Change(int[] array)
- {
- //изменяем элемент массива, можно без ref
- array[0] = 1;
- }
- void ReasssignIncorrectly(int[] array)
- {
- //пересоздание массива, т.к. аргумент не ref, это не окажет влияния на переданную ссылку
- array = new[]{2};
- }
- void ReasssignCorrectly(ref int[] array)
- {
- //пересоздается успешно, т.к. ref
- array = new[]{3};
- }
- var a = new int[1];
- Console.WriteLine(a[0]);
- Change(a);
- Console.WriteLine(a[0]);
- //не изменит массив
- ReasssignIncorrectly(a);
- Console.WriteLine(a[0]);
- ReasssignCorrectly(ref a);
- Console.WriteLine(a[0]);
- 0
- 1
- 1
- 3
Add Comment
Please, Sign In to add comment