Assigning Arrays |
|
|
Just as you can copy the contents of one variable to another, for example strA = strB, you can also copy the contents of one array to another. There are two primary ways of doing so. The first involves the Clone method, which creates a shallow copy of an array to a new array variable. A shallow copy of an array copies only the elements of the array, whether they are reference types or value types, but it does not copy the objects that the references refer to. The references in the new array point to the same objects that the references in the original array point to. In other words, for arrays of primitive data types the Clone method makes a copy of the array. Imagine, for instance, that you wanted to copy an array of bytes from one location (oldCopy) to another (newCopy). You could do it by using the Clone method. newCopy = oldCopy.Clone The following code segment demonstrates that the Clone method does not make a copy of the array contents: A similar result can be obtained through the CopyTo command.
|