C# - Array Copying using CopyTo( )-Help
c#
Solution
This works:
int[] intArray = new int[] { 10, 34, 67, 11 };
Array copyArray = Array.CreateInstance(typeof(int), intArray.Length);
intArray.CopyTo(copyArray, 0);
foreach (var i in copyArray)
Console.WriteLine(i);
You had one extra "intArray" in your Array.CreateInstance line.
That being said, this can be simplified if you don't need the Array.CreateInstance method (not sure if that's what you're trying to work out, though):
int[] intArray = new int[] { 10, 34, 67, 11 };
int[] copyArray = new int[intArray.Length];
intArray.CopyTo(copyArray, 0);
Even simpler:
int[] intArray = new int[] { 10, 34, 67, 11 };
int[] copyArray = (int[])intArray.Clone();
Problem
I have to copy the following int array in to Array : ``` int[] intArray=new int[] {10,34,67,11}; ``` i tried as ``` Array copyArray=Array.CreateInstance(typeof(int),intArray.Length,intArray); intArray.CopyTo(copyArray,0); ``` But ,it seems i have made a mistake,so i did not get the result.