Easiest way to Rotate a List in c#

后端 未结 16 3136
鱼传尺愫
鱼传尺愫 2020-12-01 07:06

Lists say I have a list List {1,2,3,4,5}

Rotate means:

=> {2,3,4,5,1} => {3,4,5,1,2} => {4,5,1,2,3}
16条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 07:54

    I use this one:

    public static List Rotate(this List list, int offset)
    {
        return list.Skip(offset).Concat(list.Take(offset)).ToList();
    }
    

提交回复
热议问题