AEvalT Function (Array OfT, ActionT) | |
Execute a code block for each element in an array.
Namespace:
XSharp.RT
Assembly:
XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax FUNCTION AEval<T>(
aArray AS ARRAY OF<T>,
cbBlock AS Action<T>
)
AS ARRAY OF<T>
public static Array Of<T> AEval<T>(
Array Of<T> aArray,
Action<T> cbBlock
)
Request Example
View SourceParameters
- aArray
- Type: Array OfT
The array to traverse. - cbBlock
- Type: ActionT
The code block to execute.
Type Parameters
- T
Return Value
Type:
Array OfT
A reference to
aArray.
The return value of the code block or is ignored — to assign the return value to each element in the array, use the AEvalA() function.
Remarks
AEval() passes the element value and the element index as arguments.
AEval() makes no assumptions about the contents of the array elements it is passing.
It is assumed that the supplied code block knows what type of data will be in each element.
AEval() is similar to DBEval() which executes code for each record of a database file.
Like DBEval(), AEval() can be used as a primitive for the construction of iteration commands for both simple and complex array structures.
Tip |
---|
In Visual Objects 2 different functions were introduced: AEval() and AEvalOld(). The difference between these functions was that AEval() was only calling the codeblock with one parameter (the element in the array), where AEvalOld() was also passing in a second parameter (the array index). Inside X# this difference no longer exists. So AEval() and AEvalOld() are doing the same thing in X#.
|
Examples
This example displays the contents of a one-dimensional array:
1LOCAL aArray[6]
2AFill(aArray, "Hi All!")
3AEval(aArray, {|Element| QOut(Element)})
This example uses AEval() to display an array of file names and file sizes returned from the Directory() function:
1LOCAL aFiles := Directory("*.dbf")
2LOCAL nTotal := 0
3AEval(aFiles, {|aDBFFile | QOut(PadR(aDBFFile[F_NAME], 10), ;
4 aDBFFile[F_SIZE], nTotal += aDBFFile[F_SIZE]})
5? "Total bytes:", nTotal
See Also