public class Class2 : IComparer
{
#region IComparer Members
/// <summary>
/// Compares two objects (assumed to be Customers) based on country then state.
/// </summary>
/// <param name="x">The first customer to compare</param>
/// <param name="y">The second customer to compare</param>
/// <returns>0 if x and y are equal, a positive number if x is greater than y, a negative number if x is less than y.</returns>
/// <remarks>It is assumed that the list is ordered by country first, then state. This does not take
/// into account if a country does not have states.</remarks>
public int Compare(object x, object y)
{
Customer c1 = (Customer)x;
Customer c2 = (Customer)y;
int countryCompare = String.Compare(c1.Country, c2.Country);
if (coutnryCompare == 0) //the countries are the same.
{
return String.Compare(c1.State, c2.State);
}
return countryCompare; //Since they weren't equal, return the differnce.
}
#endregion
}