System.Array.Copy(MyIntArray, MySecondIntArray, 2)
The CopyTo method is another one I really love. This can copy the elements of an array to any object implementing the IList interface. On catch here though, it's only supported in the 1.1 version of the framework.
MyArrayList = System.Array.CopyTo(MyIntArray, 0)
The SharedCopy method does exactly what you think it will do, copy an array or pieces of an array to another array. Remember though, you may me copying reference types so approach it accordingly
The Clone method is similar to copy, it makes a clone of the original array.
However, just like copy, you have to be careful when you use clone becuase it makes a Shallow Copy (Shallow Clone) of the objects if they are reference types. As such, if you manipulate the second array it will change the values of the first array and vice versa! Remember also that this has NOTHING to do with Passing ByVal or ByRef.
You can pass the cloned array ByVal, change its values, and both Array1 and Array2 will have their values changed!
MySecondIntArray = MyIntArray.Clone
© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext