Compares two objects.

Namespace:  Gallio.Framework
Assembly:  Gallio (in Gallio.dll) Version: 3.3.0.0 (3.3.610.0)

Syntax

C#
public int Compare<T>(
	T left,
	T right
)
Visual Basic (Declaration)
Public Function Compare(Of T) ( _
	left As T, _
	right As T _
) As Integer

Parameters

left
Type: T
The left object, may be null.
right
Type: T
The right object, may be null.

Type Parameters

T
The object type.

Return Value

A value less than zero if the left object if less than the right object, zero if the left and right objects are equal, or greater than zero if the left object is greater than the right object.

Implements

IComparisonSemantics..::.Compare<(Of <(T>)>)(T, T)

Remarks

Rules applied:

  • If both objects are null, returns 0.
  • If both objects are referentially equal, returns true.
  • If the objects are both instances of the same simple enumerable type (), then compares each pair of values until a non-equal pair is found at which point the result of that comparison is returned. If one enumeration runs out of values than the other, then it is considered to be less than the other.
  • If the objects implement IComparable<(Of <(T>)>), uses it to determine order.
  • If the objects implement IComparable, uses it to determine order.
  • Otherwise no deterministic comparison is possible so throws an exception.

The ordering of nulls is determined by CompareTo(Object) except when comparing collections. If one collection happens to be null but not the other then it is considered less than the other.

Exceptions

ExceptionCondition
System..::.InvalidOperationExceptionThrown if the values cannot be ordered.

See Also