In case if you want to implement your own Array.Copy method.
Static method which is of generic type.
static void MyCopy<T>(T[] sourceArray, long sourceIndex, T[] destinationArray, long destinationIndex, long copyNoOfElements) { long totaltraversal = sourceIndex + copyNoOfElements; long sourceArrayLength = sourceArray.Length; //to check all array's length and its indices properties before copying CheckBoundaries(sourceArray, sourceIndex, destinationArray, copyNoOfElements, sourceArrayLength); for (long i = sourceIndex; i < totaltraversal; i++) { destinationArray[destinationIndex++] = sourceArray[i]; } }
Boundary method implementation.
private static void CheckBoundaries<T>(T[] sourceArray, long sourceIndex, T[] destinationArray, long copyNoOfElements, long sourceArrayLength) { if (sourceIndex >= sourceArray.Length) { throw new IndexOutOfRangeException(); } if (copyNoOfElements > sourceArrayLength) { throw new IndexOutOfRangeException(); } if (destinationArray.Length < copyNoOfElements) { throw new IndexOutOfRangeException(); } }