14.3. Implement a Comparable Type


You need to provide a mechanism that allows you to compare custom types, enabling you to easily sort collections containing instances of those types.


To provide a standard comparison mechanism for a type, implement the generic System.IComparable(Of T) interface. To support the comparison of a type based on more than one characteristic, create separate types that implement the generic System.Collections.Generic.IComparer(Of T) interface.


The nongeneric System.IComparable and System.Collections.IComparer interfaces, available prior to .NET Framework 2.0, still exist but do not use generics to ensure type safety. If you use these interface, you must take extra precautions to ensure the objects ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.