Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arrange List<> in ascending order

Tags:

c#

linq

I have a list whose type is string which i want to arrange in ascending order

listCustomFields = new List<String>() { "FirstName", "MiddleName", "Class" };
like image 434
Murtaza Munshi Avatar asked Aug 31 '13 08:08

Murtaza Munshi


2 Answers

You can use LINQ OrderBy method (it will generate new List<string> with items sorted):

var ordered = listCustomField.OrderBy(x => x).ToList();

or List<T>.Sort method (it will sort the list in place):

listCustomField.Sort();
like image 144
MarcinJuraszek Avatar answered Oct 13 '22 10:10

MarcinJuraszek


use this

listCustomFields.sort();
like image 43
Amit Bisht Avatar answered Oct 13 '22 11:10

Amit Bisht