public class MyComparer : IComparer
{
ArrayList countries = new ArrayList();
public MyComparer()
{
countries.Add("Australia");
countries.Add("United States");
countries.Add("France");
countries.Add("Canada");
countries.Add("Germany");
countries.Add("United Kingdom");
}
public int Compare(object x, object y)
{
int namX;
int namY;
namX = countries.IndexOf(x);
namY = countries.IndexOf(y);
if (namX.CompareTo(namY) > 0)
return 1;
else if (namX.CompareTo(namY) == -1)
return -1;
else
return 0;
}
}This code is to create custom ordering using IComparer Interface. Sorting does ascending or descending but using these codes you can sort w.r.t to the given collection's order.
