References


How can I sort generic list DESC and ASC?



Sources


1. Use Linq


var ascendingOrder = li.OrderBy(i => i);

var descendingOrder = li.OrderByDescending(i => i);



2. Not use Linq


li.Sort((a, b) => a.CompareTo(b)); // ascending sort

li.Sort((a, b) => -1* a.CompareTo(b)); // descending sort



3. Make to list.


li = li.OrderBy(i => i).ToList();

반응형

+ Recent posts