开发者

sorting elements of a list

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜