that sounds like it might work, can you elaborate/provide examples? so
i would create a class called ProgramComparer, for example, which would
read the value of my property "MTP" and then i could simply call
m_Arraylist.sort(ProgramComparer) ?
The class below is a simple IComparer that can be used to sort a list
of integers in reverse order.
class ReverseIntComparer : IComparer<int>
{
public int Compare(int x, int y)
{
return y.CompareTo(x);
}
}
Here is the same comparer, but without generics
class ReverseIntComparer : IComparer
{
public int Compare(object x, object y)
{
int x1 = (object) x;
int y1 = (object) y;
return y1.CompareTo(x1);
}
}
To sort an arraylist of integers in reverse order I would simply do
something like this:
myArraylist.Sort(new ReverseIntComparer());
Here is a final example that sorts people by looking at their last
name first.
class Person
{
public string FirstName;
public string LastName;
}
class PersonComparer : IComparer<Person)
{
public int Compare(Person a,Person b)
{
int compareLastName = a.LastName.CompareTo(b.LastName);
if(compareLastName != 0)
return compareLastName;
// The same last name
return a.FirstName.CompareTo(b.FirstName);
}
}