可以实现一个IComparable接口的CompareTo方法,或者是给予List的Sort扩展方法,传入委托实现,举个例子:

list.Sort((a, b) => {
                var o = a.sortIndex - b.sortIndex;
                return o;
            })

其实我们还可以根据OrderBy扩展方法来实现:

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

对于orderby可以参考:https://stackoverflow.com/questions/3007470/custom-sort-logic-in-orderby-using-linq

给予OrderBy的扩展方法实现:http://www.cnblogs.com/94cool/p/9314685.html

具体项目需求具体实现。相比较来讲,orderby的性能比sort要好。

相关文章:

  • 2021-06-19
  • 2022-12-23
  • 2021-11-19
  • 2020-01-16
  • 2022-12-23
  • 2021-06-19
  • 2021-07-07
猜你喜欢
  • 2022-12-23
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2021-10-22
  • 2022-12-23
相关资源
相似解决方案