How do I truncate a list in C#?
var itemsOneThroughTwenty = myList.Take(20);
var itemsFiveThroughTwenty = myList.Skip(5).Take(15);
You can use List<T>.GetRange()
:
var subList = myList.GetRange(0, 20);
From MSDN:
Creates a shallow copy of a range of elements in the source
List<T>
.
public List<T> GetRange(int index, int count)