Sort part of an ArrayList

  • Thread starter Thread starter Curious
  • Start date Start date
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.
 
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
 
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....
}
}
}
 
Back
Top