Y2theZ
Y2theZ

Reputation: 10412

C# change the sorting algorithm of a list

Is there a way I can change the sorting algorithm of a List<string> in C#?

If I have a list

List<string> Names = new List<string>();

When sorting I call

Names.Sort();

Is the a way I can override the default algorithm that is used?

Second question

What about the build in sorting of a webgrid in ASP.NET MVC3? The Webgrid has a build in sorting, if you specify canSort=true you can click on the header and rows will be sorted alphabetically. is there a way I can change that too?

Thanks

Upvotes: 0

Views: 639

Answers (1)

Anders Abel
Anders Abel

Reputation: 69280

There are overloads to List<>.Sort() that accepts custom comparers.

Upvotes: 2

Related Questions