Click or drag to resize

Functions.ACloneShallow Method (Array)

Duplicate an array without its subarrays.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.16
 FUNCTION ACloneShallow(
	aSource AS ARRAY
Request Example View Source


Type: Array
The array to duplicate.

Return Value

Type: Array
A duplicate of aSource without its subarrays.
ACloneShallow() creates a duplicate of aSource.
Unlike AClone(), ACloneShallow() does not check to see if aSource contains subarrays and does not copy them if they exist.
ACloneShallow() also works differently from AClone() in that AClone() duplicates by recursively traversing the source array.
ACloneShallow() first builds the target array structure from information derived directly from the source array, then copies the first-dimension values to the target.
If an element of the source array is a subarray, the target array will contain a reference to the subarray.
This example creates an array and duplicates it using ACloneShallow().
Moreover, by changing an element in the source subarray that automatically affects the target subarray, it
illustrates that subarrays are copied by reference:
1LOCAL aSource, aTarget, aSourceSubArray AS ARRAY
2aSourceSubArray := {3,4,5}
3aSource := {1, 2, aSourceSubArray}
4aTarget := ACloneShallow(aSource)
5// aTarget is {1, 2, {3,4,5}}
6// Now change the source subarray
7aSourceSubArray[3] := 100
8// The change is also reflected in aTarget
9// aTarget is {1, 2, {3,4,100}}
See Also