Solved

Sort Arraylist of String[]

Posted on 2007-11-28
5
979 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 47
How can I use SQL Stored Procedure to return FedEx Zone 17 41
Problem of RegEx to match the first occurence of 10 35
Tool Box 2 34
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

911 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

18 Experts available now in Live!

Get 1:1 Help Now