Click or drag to resize

ASortEx Function

X#
Sort an array.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.24 GA
Syntax
 FUNCTION ASortEx(
	aTarget AS ARRAY,
	nStart AS USUAL,
	nCount AS USUAL,
	compBlock AS Codeblock
) AS ARRAY
Request Example View Source

Parameters

aTarget
Type: Array
The array to sort.
nStart
Type: Usual
The starting element.
The default value is 1.
nCount
Type: Usual
The number of elements to process from nStart.
The default is all elements to the end of the array.
compBlock
Type: Codeblock
The codeblock that is called to sort the elements. Should return signed integer, like IComparer.Compare

Return Value

Type: Array
A reference to aTarget.
Remarks
ASortEx() sorts all or part of an array.
The array may contains USUALs of mixed types.
Examples
This example creates an array of five unsorted elements, sorts the array in ascending order, then sorts the array in descending order using a code block:
X#
 1   LOCAL testArray AS ARRAY
 2   testArray  := {"Fred", "Kate", "Fred", "ALVIN", "friend"}
 3   ASortEx(testArray, 1,ALen(testArray), {|a,b|
 4   if upper(a) < upper(b)
 5    return -1
 6elseif upper(a) > upper(b)
 7   return 1
 8   endif
 9   return 0
10   })
11   // The sort order after the code has run is ALVIN, Fred, Fred, friend, Kate
See Also