| Bruce Wood 2006-06-17, 7:02 pm |
| Yes you could, if you used the version of ArrayList.Sort that takes an
IComparer as its argument:
public class MySpecialComparison : IComparer
{
public int Compare(object x, object y)
{
MyObject a = (MyObject)x;
MyObject b = (MyObject)y;
if (a == b) return 0;
if (a == null) return 1;
if (b == null) return -1;
... do whatever magic is needed to compare a and b ...
}
}
then later:
myArrayOfMyObject.Sort(new MySpecialComparer());
Doug wrote:
> I know there's a sort option on an ArrayList but how accurately would
> it work? It would have to know a lot of information about the object
> that is being put into the ArrayList wouldn't it? For example, if you
> put a custom built object into it and wanted to sort on one of the
> properties within the object, you certainly couldn't do it just by
> saying .Sort could you?
|