Click or drag to resize

ASortFunc Function

X#
Sort an array.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.24 GA
Syntax
 FUNCTION ASortFunc(
	aTarget AS ARRAY,
	nStart AS USUAL,
	nCount AS USUAL,
	compFunction AS Func<USUAL, USUAL, LONG>
) 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.
compFunction
Type: FuncUsual, Usual, Long
The function that is called to sort the elements. Should return signed integer, like IComparer.Compare

Return Value

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