Click or drag to resize

AAddT Function (Array OfT, T)

X#
Add a new element to the end of an array.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.21
Syntax
 FUNCTION AAdd<T>(
	aTarget AS ARRAY OF<T>,
	uNewElement AS T
)
 AS T
Request Example View Source

Parameters

aTarget
Type: Array OfT
The array to add a new element to.
uNewElement
Type: T
The value assigned to the new element.
If uNewElement is another array, the new element in the target array will contain a reference to the array specified by uNewElement, rather than the array itself.

Type Parameters

T
The type of the array elements

Return Value

Type: T
The value of uNewElement.
Remarks
AAdd() increases the actual length of the target array by one.
The newly created array element is assigned the value specified by uNewElement.
AAdd() is used to dynamically increase the size of an array.
It is useful for building dynamic lists or queues.
A good example of this is the GetList array used to hold Get objects.
AAdd() is similar to ASize() but only adds one element at a time; ASize() can change an array to a specified size.
AAdd(), however, has the advantage that it can assign a value to the new element, while ASize() cannot.
AAdd() seems similar to AIns(), but they are different: AIns() moves elements within an array, but it does not change the array's length.
Examples
These examples show what happens when you invoke AAdd() more than once:
X#
1LOCAL aArray AS ARRAY
2aArray := {}                    // aArray is an empty array
3AAdd(aArray, 5)            // aArray is {5}
4AAdd(aArray, 10)            // aArray is {5, 10}
5AAdd(aArray, {12, 10})        // aArray is {5, 10, {12, 10}}
6AAdd(aArray, 1, 2 )        // aArray is  5, 2, 10, {12, 10}}
See Also