views:

461

answers:

3

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?

+8  A: 
subList = text.Skip(2).ToList()

Skip(n) returns an IEnumerable<> with all elements except the first n.

When you really need a list after that, ToList() converts it back.

Timbo
+11  A: 

This will work even without LINQ:

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

Edit: Fixed a typo.

Vojislav Stojkovic
+3  A: 

If you're on 3.5, then there are a lot of new and interesting methods available on List. Just check out the section 'Extension methods' here: http://msdn.microsoft.com/en-us/library/d9hw1as6.aspx

Gerrie Schenck