Is Array.Copy safe when the source and destination are the same array?
c#
Solution
Yes, it is safe. It is documented how the method should behave in this case:
If sourceArray and destinationArray overlap, this method behaves as if the original values of sourceArray were preserved in a temporary location before destinationArray is overwritten.
Problem
I'm currently using Array.Copy to shift an array as such: ``` Array.Copy(array, 0, array, 1, array.Length - 1); ``` It's noticeable faster than using a loop. I know that similar functions in other languages (eg. memcpy) are undefined or sometimes break when the compiler gets too aggressive. Is it reasonable to consider this safe in .NET?