How to Get a Sublist in C#

前端 未结 6 1628
走了就别回头了
走了就别回头了 2021-02-02 05:09

I have a List and i need to take a sublist out of this list. Is there any methods of List available for this in .NET 3.5?

6条回答
  •  萌比男神i
    2021-02-02 05:34

    Reverse the items in a sub-list

    int[] l = {0, 1, 2, 3, 4, 5, 6};
    var res = new List();
    res.AddRange(l.Where((n, i) => i < 2));
    res.AddRange(l.Where((n, i) => i >= 2 && i <= 4).Reverse());
    res.AddRange(l.Where((n, i) => i > 4));
    

    Gives 0,1,4,3,2,5,6

提交回复
热议问题