Clone Value Array : Array Clone « Data Structure « C# / CSharp Tutorial






using System;

class MainClass
{
   static void Main()
   {
      int[] orignalArray = { 1, 2, 3 };                    
      int[] cloneArray = (int[])orignalArray.Clone();         

      cloneArray[0] = 10;
      cloneArray[1] = 20;
      cloneArray[2] = 30;

      foreach (int i in orignalArray)
         Console.WriteLine(i);

      foreach (int i in cloneArray)
         Console.WriteLine(i);
   }
}
1
2
3
10
20
30








11.11.Array Clone
11.11.1.Clone array with reference data inside
11.11.2.Clone Value Array
11.11.3.Cloning arrays