how can i开发者_StackOverflow社区 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");
you can sort then reverse:
List<string> lstStr = new List<string>() { "bac", "abc", "cba" };
lstStr.Sort();
lstStr.Reverse();
lstStr.Sort((x, y) => string.Compare(y, x));
in .Net 3.5, using Linq, you are able to write
var orderdList = lstStr.OrderByDescsending();
You can easy sort by descending using linq:
var lstStr = new List<string>() { "bac", "abc", "cba" };
lstStr = lstStr.OrderByDescending(x => x).ToList();
精彩评论