For Programmers: Free Programming Magazines  


Home > Archive > C# > June 2006 > Re: String- Dynamically adding









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: String- Dynamically adding
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?


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com