本文介绍了LINQ的OrderBy,启动与特定的号码,然后返回到最低的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一组数据,我想重新排序开始一个具体的数字,然后达到最高数字时,返回到最低,然后递增搬动。
例如,对于序列(1,2,3,4,5,6)中,如果4是特定号码,该命令将成为(4,5,6,1,2 ,3)
有可能与LINQ和放大器,; C#
解决方案
列表< INT>列表=新列表与所述; INT>(){1,2,3,4,5,6};
INT NUM = 4;
VAR newList = list.SkipWhile(X =>!x = NUM)
.Concat(list.TakeWhile(X =>!x = NUM))
.ToList();
I have a set of data which I'd like to re-order starting with a specific number and then, when the highest number is reached, go back to the lowest and then carry on incrementing.
For example, for the sequence (1,2,3,4,5,6), if 4 was the specific number, the order would become (4,5,6,1,2,3).
Is that possible with linq & c#?
解决方案
List<int> list = new List<int>() { 1, 2, 3, 4, 5, 6 };
int num = 4;
var newList = list.SkipWhile(x=>x!=num)
.Concat(list.TakeWhile(x=>x!=num))
.ToList();
这篇关于LINQ的OrderBy,启动与特定的号码,然后返回到最低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!