Sort part of an ArrayList

C

Curious

I have:

ArrayList mPreviousComments = new ArrayList(new string[]{"Please
select a comment:"});

mPreviousComments contains multiple items with the first one being
"Please select a comment:". For example, it contains the following
{"Please select a comment:", "No user intervention is necessary",
"Procedure completed", "Error occured during executing"...}

Now I'll need to sort mPreviousComments in alphabetical order with the
exception that the first item will always be "Please select a
comment:". How to sort the rest of the list? mPreviousComments.Sort()
would sort the entire list.
 
A

Andrew Morton

Curious said:
What parameters to pass to the overload method?

Are you using Notepad (or some other text editor) to create your programs
in, such that you don't have access to the help? In that case you can still
look it up through msdn.microsoft.com.

Andrew
 
M

mangin.nicolas

I have:

ArrayList mPreviousComments = new ArrayList(new string[]{"Please
select a comment:"});

mPreviousComments contains multiple items with the first one being
"Please select a comment:". For example, it contains the following
{"Please select a comment:", "No user intervention is necessary",
"Procedure completed", "Error occured during executing"...}

Now I'll need to sort mPreviousComments in alphabetical order with the
exception that the first item will always be "Please select a
comment:". How to sort the rest of the list? mPreviousComments.Sort()
would sort the entire list.

Why don't you create a new sort class for your arraylist?
ex:

public class NewSorting : IComparer<string>
{
public int Compare(string x, string y)
{
if(x != "Please select a comment:")
{
blabla....
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top