List<int> Sort

G

Guest

I'm working in Visual Studio 2005, .NET 2.0, and C#.

I've got the below. I need to be sure that Sort() does the sorting in
ascending order. Writing an IComparer Class for this seems like massive
overkill. Any suggestions on how to assure an asending order sort for my
integer List as simply as possible?

Thanks,
Randy

List<int> numbers = new List<int>();
numbers.Add(3);
numbers.Add(7);
numbers.Add(4);

numbers.Sort(); //Needs to assure ascending order
 
T

Tom Porterfield

randy1200 said:
I'm working in Visual Studio 2005, .NET 2.0, and C#.

I've got the below. I need to be sure that Sort() does the sorting in
ascending order. Writing an IComparer Class for this seems like massive
overkill. Any suggestions on how to assure an asending order sort for my
integer List as simply as possible?

Thanks,
Randy

List<int> numbers = new List<int>();
numbers.Add(3);
numbers.Add(7);
numbers.Add(4);

numbers.Sort(); //Needs to assure ascending order

System.Int32 implements IComparable such that the list should always be
sorted ascending. So nothing more for you to do.
 

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