-
Notifications
You must be signed in to change notification settings - Fork 3
OrderByDescending
Yasser Moradi edited this page Sep 1, 2015
·
1 revision
Description:
OrderByDescending specifies how a collection should be ordered.
Sample:
let sortedResult = [1,3,2].asEnumerable().orderByDescending(num => num).toArray();
Description:
By using .orderByDescending(person => person.fName), we can easily order data in a source collection.
Most new developers make use of the same function twice .orderByDescending(person => person.fName).orderByDescending(person => person.lName)
and thinks that will do the ordering in multiple columns.
But it always does the order by the column you specified in the last OrderBy() method.
You should use .thenBy and .thenByDescending methods to achieve this goal.
Sample:
let people = [ { fName : 'A', lName : 'A' }, { fName: 'B' , lName: 'B" } ];
let sortedPeople = people.asEnumerable().orderByDescending(p => p.fName).thenBy(p => p.lName).toArray()