Hi Dear,
I have one query. I have one arraylist in which i stored sturct object values now
i want to sort arraylist using struct object.
so plz help me.
Thnx
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AlanPosted Oct 8, 2008, 5:13 AM
You first need to create a helper class which implements IComparer and code its Compare() method to provide a sort order for your structs. This method should return the following int values when two structs, x and y, are compared to each other:
Less than zero
if x is less than y.
Zero
if x equals y.
Greater than zero
if x is greater than y.
You then need to create an instance of this class and pass it to the overload of ArrayList.Sort() which takes an IComparer parameter. See the MSDN example below (or google for others) to get an idea of how to do this:
http://msdn.microsoft.com/en-us/library/0e743hdt.aspx