The ArrayCopyTo() method copies all elements of the current one-dimensional array to the specified one-dimensional array, starting from the specified target array index. The index is specified as a 32-bit integer.
In C#, the CopyTo() method is used to copy the elements of one array to another array. In this method you can set the starting index to copy from the source array.
The following is an example showing the usage of the CopyTo(,) method of the array class in C#:
The ArrayCopyTo() method copies all elements of the current one-dimensional array to the specified one-dimensional array, starting from the specified target array index. Indexes are specified as 32-bit integers.
In C#, the CopyTo() method is used to copy the elements of one array to another array. In this method you can set the starting index to copy from the source array.
The following is an example showing the usage of the CopyTo(,) method of the array class in C#:
using System; class Program { static void Main() { int[] arrSource = new int[4]; arrSource[0] = 5; arrSource[1] = 9; arrSource[2] = 1; arrSource[3] = 3; int[] arrTarget = new int[4]; // CopyTo() method arrSource.CopyTo(arrTarget,0 ); Console.WriteLine("Destination Array ..."); foreach (int value in arrTarget) { Console.WriteLine(value); } } }
Array.Clone() method in C# Clone array. Here we have an array of strings −
using System; class Program { static void Main() { string[] arr = { "one", "two", "three", "four", "five" }; string[] arrCloned = arr.Clone() as string[]; Console.WriteLine(string.Join(",", arr)); // cloned array Console.WriteLine(string.Join(",", arrCloned)); Console.WriteLine(); } }
The above is the detailed content of System.ArrayCopyTo() and System.ArrayClone() in C#. For more information, please follow other related articles on the PHP Chinese website!