Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

AFCollection(T).Sort Method (Int32, Int32, IComparer(T))

AFCollection(T).Sort Method (Int32, Int32, IComparer(T))

  • Last UpdatedNov 18, 2025
  • 3 minute read
AFCollection(T).Sort Method (Int32, Int32, IComparer(T))
Sorts the items in a range of items in the collection using the specified comparer.

Namespace:  OSIsoft.AF
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182

Syntax

public void Sort(
	int index,
	int count,
	IComparer<T> comparer
)
Public Sub Sort ( 
	index As Integer,
	count As Integer,
	comparer As IComparer(Of T)
)

Dim instance As AFCollection
Dim index As Integer
Dim count As Integer
Dim comparer As IComparer(Of T)

instance.Sort(index, count, comparer)
public:
void Sort(
	int index, 
	int count, 
	IComparer<T>^ comparer
)
member Sort : 
        index : int * 
        count : int * 
        comparer : IComparer<'T> -> unit 

Parameters

index
Type: SystemInt32
The zero-based starting index of the range to sort.
count
Type: SystemInt32
The length of the range to sort.
comparer
Type: System.Collections.GenericIComparerT
The IComparerT implementation to use when comparing items in the collection, or a to use the default comparer for type T.

Exceptions

ExceptionCondition
InvalidOperationException If the size of the collection is too large to perform the operation. This occurs when the number of items in the collection is greater than a page size and the IsPaging property is .

Remarks

If a comparer is provided, the items of the collection are sorted using the specified IComparerT implementation. If a is specified for the comparer, the default comparer is used to sort the items in the collection. If the item has a name, then the default comparer will normally sort the collection based upon the item's name.

This method uses Array.Sort, which uses the QuickSort algorithm. This implementation performs an unstable sort; that is, if two items are equal, their order might not be preserved. In contrast, a stable sort preserves the order of the items that are equal.

On average, this method is an O(n log n) operation, where n is Count; in the worst case it is an O(n^2) operation.

Version Information

AFSDK


See Also

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in