Reputation: 11
how can i use .Sort() to sort a list in reverse order:
List<string> lstStr = new List<string>() { "bac", "abc", "cba" };
lstStr.Sort(); //i want something like Sort("desc");
Upvotes: 1
Views: 136
Reputation: 8645
in .Net 3.5, using Linq, you are able to write
var orderdList = lstStr.OrderByDescsending();
Upvotes: 3
Reputation: 53705
You can easy sort by descending using linq:
var lstStr = new List<string>() { "bac", "abc", "cba" };
lstStr = lstStr.OrderByDescending(x => x).ToList();
Upvotes: 1
Reputation: 14565
you can sort then reverse:
List<string> lstStr = new List<string>() { "bac", "abc", "cba" };
lstStr.Sort();
lstStr.Reverse();
Upvotes: 4