使用LINQ列表进行排序范围 [英] Sorting range of list using LINQ
本文介绍了使用LINQ列表进行排序范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道是否有可能使用LINQ千万不等的排序,比如我有一个数字列表:
I was wondering if it is possible to do ranged sort using LINQ, for example i have list of numbers:
列表< INT>数=新的List< INT>
- 1
- 2
- 3
- 15℃; - 排序
- 11 LT; - 排序
- 13 LT; - 排序
- 10 LT; - 排序
- 6
- 7
- 等
- 1
- 2
- 3
- 15 <-- sort
- 11 <-- sort
- 13 <-- sort
- 10 <-- sort
- 6
- 7
- etc.
只需用 numbers.Skip(3)。取(4).OrderBy(布拉布拉)
将工作,但它只会返回那些包含4个数字的新列表。是否是某种可能迫使LINQ到自身工作,而无需返回一个新的部分列表,或接收与排序一部分齐全的企业之一? !
感谢您的任何答案
Simply using numbers.Skip(3).Take(4).OrderBy(blabla)
will work, but it will return a new list containing only those 4 numbers. Is is somehow possible to force LINQ to work on itself without returning a new "partial" list or to receive complete one with sorted part?
Thanks for any answer!
推荐答案
尝试是这样的:
var partiallySorted = list.Where(x => x < 11)
.Concat(list.Where(x => x >= 11 && x <=15).OrderBy(/*blah*/)))
.Concat(list.Where(x => x > 15));
这篇关于使用LINQ列表进行排序范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文