System.IComparable

Added in .NET 1.1
This interface provides a CompareTo method which is used to determine the sort order of the implementing types.
Provides a default sort order
This interface is implemented by types that can be sorted, strings for example can be alphabetized, any given string can be compared with another string to determine which should come first in an ordered list.
Provides a comparer check (for sorting) when there is only on way of ordering the objects (implemented inside the class)
Provides a method of comparing two objects of a particular type.
Great for ordering of simple objects


CompareTo Method

You must implement this method


int IComparable.CompareTo(object obj) 
{
   myobject my = (myobject)obj;
   return String.Compare(this.MySortProperty, myobject.MySortProperty)
}

In this example String.Compare is used because the property used for comparison is a string.
Need an Integer example ?


System.Collections.IComparer

Added in .NET 1.1
System.Collections.IComparer
Allows you to define and use multiple comparer checks (implemented outside the class)


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext