What is the C# code to split an array from a given range. Eg:
int[] arr = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}
I want to split arr it into two arrays. One from 0th to 5th index and the other from 6th to 20th index.
In Java Arrays.copyOfRange() can be used for this process. What is the C# code for this?
arr.Take(5).ToArray()andarr.Skip(5).ToArray()Array.Copyis more efficient than enumerating the array until you are at given indexes and create a new withToArray. For small arrays this is micro-optimization. But since the uglyArray.Copyis hidden in an extension method you don't need to care about readable code.