Solved

Sort Arraylist of String[]

Posted on 2007-11-28
5
978 Views
Last Modified: 2013-12-17
I have an arraylist that contains string [] objects.  The arraylist looks like

arraylist.add(new string [] {name, phone});

How can I sort the arraylist by name?
0
Comment
Question by:Rowdyone52
5 Comments
 
LVL 4

Expert Comment

by:aumudin
Comment Utility
0
 

Author Comment

by:Rowdyone52
Comment Utility
That doesnt use arraylists.
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 500 total points
Comment Utility
Create a class that implements IComparer and use that to sort the ArrayList:
public class PhoneComparer : IComparer  {

   int IComparer.Compare(object x, object y) {

      return string.Compare(((string[])x)[0], ((string[])y)[0]);

   }

}
 

arraylist.Sort(new PhoneComparer());

Open in new window

0
 
LVL 22

Expert Comment

by:JimBrandley
Comment Utility
It's pretty easy to do if you write your own IComparer. There's an example of how to do that here:

http://msdn2.microsoft.com/en-us/library/0e743hdt.aspx

Jim
0
 

Author Closing Comment

by:Rowdyone52
Comment Utility
Excellent!  Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now