AAdd Function (Array, Usual) | |
Add a new element to the end of an array.
Namespace:
XSharp.RT
Assembly:
XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax FUNCTION AAdd(
aTarget AS ARRAY,
uNewElement AS USUAL
) AS USUAL
public static Usual AAdd(
Array aTarget,
Usual uNewElement
)
Request Example
View SourceParameters
- aTarget
- Type: Array
The array to add a new element to. - uNewElement
- Type: Usual
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.
Return Value
Type:
Usual
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:
1LOCAL aArray AS ARRAY
2aArray := {}
3AAdd(aArray, 5)
4AAdd(aArray, 10)
5AAdd(aArray, {12, 10})
6AAdd(aArray, 1, 2 )
See Also