Defines a method that a type implements to compare two objects.
mscorlib (in mscorlib.dll)
Public Interface IComparer(Of In T)
The type of objects to compare.
Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
The following example implements the IComparer<T> interface to compare objects of type Box according to their dimensions. This example is part of a larger example provided for the Comparer<T> class.
' This class is not demonstrated in the Main method
' and is provided only to show how to implement
' the interface. It is recommended to derive
' from Comparer<T> instead of implementing IComparer<T>.
Public Class BoxComp
Implements IComparer(Of Box)
' Compares by Height, Length, and Width.
Public Function Compare(ByVal x As Box, ByVal y As Box) As Integer Implements _
If x.Height.CompareTo(y.Height) <> 0 Then
ElseIf x.Length.CompareTo(y.Length) <> 0 Then
ElseIf x.Width.CompareTo(y.Width) <> 0 Then
Return to top Universal Windows Platform
Available since 8.NET Framework
Available since 2.0Portable Class Library
Supported in: portable .NET platformsSilverlight
Available since 2.0Windows Phone Silverlight
Available since 7.0Windows Phone
Available since 8.1