So write a class that implements it:
public class MyComparer : IComparer<MyObj>The value you return must be negative if x is less then y, 0 if x is equal to y or greater then 0 if x is greater then y.
{
public int Compare(MyObj x, MyObj y) {
// If, for example you're working with an int:
return x.IntProperty.CompareTo(y.IntProperty);
// If, perhaps, it is a string:
return string.CompareTo(x.StringProperty, y.StringProperty)
}
}
This can of course be used with things like MyCollection.Sort(new MyComparer()), really handy if you have strange objects.

0 comments:
Post a Comment