May 2010
Intermediate to advanced
1272 pages
61h 18m
English
IComparable InterfaceYou implement the IComparable interface when you want to offer custom comparison instrumentation to your objects. IComparable requires you to implement a CompareTo method that returns an Integer value which is less than zero if the instance is less than the compared object, zero if the instance equals the compared object and greater than zero if the instance is greater than the compared object. For example, imagine you want to provide a comparison to the Person class based on the length of the LastName property. Listing 13.3 shows how you can accomplish this.
Listing 13.3 Implementing the IComparable Interface

You may ...
Read now
Unlock full access