gpt4 book ai didi

c# - Linq orderby,从特定数字开始,然后返回到最低

转载 作者:IT王子 更新时间:2023-10-29 04:36:49 25 4
gpt4 key购买 nike

我有一组数据,我想从一个特定的数字开始重新排序,然后,当达到最高数字时,返回到最低数字,然后继续递增。

例如,对于序列(1,2,3,4,5,6),如果4是特定数字,则顺序将变为(4,5,6,1,2,3)。

使用 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();

关于c# - Linq orderby,从特定数字开始,然后返回到最低,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12579559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com