Search code examples
c#listlist-manipulation

c# List manipulation


If I have

List<String> text

how can I create a sub-list of all continious elements within a specific range e.g.

List<String> subList = /* all elements within text bar the first 2*/

Also are there any other useful List manipulation tips & tricks that might be useful?


Solution

  • This will work even without LINQ:

    List<String> subList = text.GetRange(2, text.Count - 2);
    

    Edit: Fixed a typo.