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

AF SDK Reference

UniversalComparer(T).Compare Method

  • Last UpdatedNov 18, 2025
  • 3 minute read
UniversalComparer(T).Compare Method
Performs a comparison of two objects of the type and sort criteria specified in the constructor and returns a value indicating whether one is less than, equal to, or greater than the other.

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

Syntax

public override int Compare(
	T x,
	T y
)
Public Overrides Function Compare ( 
	x As T,
	y As T
) As Integer

Dim instance As UniversalComparer
Dim x As T
Dim y As T
Dim returnValue As Integer

returnValue = instance.Compare(x, y)
public:
virtual int Compare(
	T x, 
	T y
) override
abstract Compare : 
        x : 'T * 
        y : 'T -> int 
override Compare : 
        x : 'T * 
        y : 'T -> int 

Parameters

x
Type: T
The first object to compare.
y
Type: T
The second object to compare.

Return Value

Type: Int32
ValueMeaning
Less than zerox is less than y.
Zerox equals y.
Greater than zerox is greater than y.

Implements

IComparerTCompare(T, T)

Exceptions

ExceptionCondition
ArgumentException Neither x nor y implements IComparable, IComparable{T}, is a Nullable{T} type, or x and y are of different types.

Remarks

The objects being compared must support the IComparable interface, the IComparable{T} interface, or is a Nullable{T} type. Comparing with any type is allowed and does not generate an exception and is considered to be less than any other object.

Examples

This example will sort the AFElement items in the array arrayElements first by type in ascending order, then by name in descending order.
AFElements allElements = db.Elements;
AFElement[] arrayElements = new AFBaseElement[allElements.Count];
allElements.CopyTo(arrayElements, 0);
UniversalComparer comparer=
    new UniversalComparer(typeof(AFElement), "Type, Name DESC");
Array.Sort(arrayElements, comparer);

Version Information

AFSDK


See Also

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