在使用LINQ排序依据自定义排序逻辑自定义、逻辑、依据、LINQ

由网友(花败ヽ亦残缺)分享简介:什么是正确的方式进行排序,我要开始的项目以下划线_,要在列表的底部字符串列表,否则一切都是按字母顺序排列。现在我做这样的事情,autoList.OrderBy(A => a.StartsWith(_)ZZZZZZ+一:一)解决方案 如果您想自定义排序,但不希望提供一个比较器,你可以把它 - SQL风格:自动列表...

什么是正确的方式进行排序,我要开始的项目以下划线_,要在列表的底部字符串列表,否则一切都是按字母顺序排列。

现在我做这样的事情,

  autoList.OrderBy(A => a.StartsWith(_)ZZZZZZ+一:一)
 

解决方案

如果您想自定义排序,但不希望提供一个比较器,你可以把它 - SQL风格:

 自动列表
.OrderBy(?一个=> a.StartsWith(_)2:1)
.ThenBy(一个=&胺a);
 
excel 排序问题

What would be the right way to sort a list of strings where I want items starting with an underscore '_', to be at the bottom of the list, otherwise everything is alphabetical.

Right now I'm doing something like this,

autoList.OrderBy(a => a.StartsWith("_") ? "ZZZZZZ"+a : a )

解决方案

If you want custom ordering, but don't want to supply a comparer, you can have it - sql style:

autoList
.OrderBy(a => a.StartsWith("_") ? 2 : 1 )
.ThenBy(a => a);

阅读全文

相关推荐

最新文章