Information Technology Reference
In-Depth Information
Cloning a reference type array results in two arrays
pointing at the same objects
. The following
code shows an example. Figure 14-17 illustrates the steps shown in the code.
class A
{
public int Value = 5;
}
class Program
{
static void Main()
{
A[] AArray1 = new A[3] { new A(), new A(), new A() }; // Step 1
A[] AArray2 = (A[]) AArray1.Clone(); // Step 2
AArray2[0].Value = 100;
AArray2[1].Value = 200;
AArray2[2].Value = 300; // Step 3
}
}
Figure 14-17.
Cloning a reference type array produces two arrays referencing the same objects.