AAddT Function (Array OfT, T, DWord) | |
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,
nElement AS DWORD
)
AS T
public static T AAdd<T>(
Array Of<T> aTarget,
T uNewElement,
uint nElement
)
Request Example
View SourceParameters
- 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.
- nElement
- Type: DWord
The position within the array of the element to which the new value is assigned. If nElement is not specified, the value is assigned to the last element.
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:
1LOCAL aArray AS ARRAY
2aArray := {}
3AAdd(aArray, 5)
4AAdd(aArray, 10)
5AAdd(aArray, {12, 10})
6AAdd(aArray, 1, 2 )
See Also