Solved

Sort Arraylist of String[]

Posted on 2007-11-28
5
982 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
ID: 20369234
0
 

Author Comment

by:Rowdyone52
ID: 20369258
That doesnt use arraylists.
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 500 total points
ID: 20369355
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
ID: 20369365
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
ID: 31597123
Excellent!  Thanks
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Google Directions API to Map URL -C#? 3 39
FInd Image Control Gridview 3 23
Vb.net threads keep increasing 2 38
Generate Unique ID in VB.NET 21 69
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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