What is the difference between Array.Copy and Array.CopyTo?

Is there any difference between Array.Copyand CopyTo? Are they just overloaded?

+3
source share
5 answers

Look carefully. Copyis a static method, while it CopyTois an instance method.

+7
source

Same functionality, different calling conventions. Copy- a static method, but CopyTo- no.

Array.Copy(arraySrc, arrayDest, arraySrc.length);
arraySrc.CopyTo(arrayDest, arraySrc.length);
+6
source

; .

MSDN:

(Array.CopyTo) System.Collections.ICollection. System.Collections.ICollection , Copy, .

+4

, , - , CopyTo, all , Copy

0


https://msdn.microsoft.com/en-us/library/k4yx47a1.aspx
https://msdn.microsoft.com/en-us/library/06x742cw.aspx,
, :

Array.CopyTo

  • .
  • .
  • .

CopyTo

-, , Array.CopyTo :

This method is equivalent to the standard C / C ++ function memmove, not memcpy.

Who CopyTodoes not have such a description.
It is true that copying part of an array is not easy, using CopyTowithout parameters to control the range. However, you can use ArraySegmentor array.Skip(offset).Take(length)to achieve it.
And there are no problems in my test.

0
source

Source: https://habr.com/ru/post/1720750/


All Articles