Sort Arraylist of String[]

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?
Rowdyone52Asked:
Who is Participating?
 
Göran AnderssonConnect With a Mentor Commented:
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
 
aumudinCommented:
0
 
Rowdyone52Author Commented:
That doesnt use arraylists.
0
 
JimBrandleyCommented:
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
 
Rowdyone52Author Commented:
Excellent!  Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.