O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Create a Comparable Object

Problem

You need to provide a mechanism that allows two custom objects to be compared.

Solution

Determine what data you want to use for the basis of your comparison, and implement the IComparable interface.

Discussion

The IComparable interface defines a single CompareTo method that accepts an object for comparison and returns an integer. The integer can take one of the following three values:

  • Zero, which means the objects are equal.

  • Less than zero (typically - 1), which means that the current object is less than the object that was supplied as a parameter.

  • Greater than zero (typically 1), which means that the current object is greater than the object that was supplied as a parameter.

You can evaluate the object contents on your ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required