How do I truncate a list in C#?

Rishi picture Rishi · Aug 7, 2010 · Viewed 12.1k times · Source

I know in python you can do something like myList[1:20] but is there anything similar in C#?

Answer

Tim Robinson picture Tim Robinson · Aug 7, 2010
var itemsOneThroughTwenty = myList.Take(20);
var itemsFiveThroughTwenty = myList.Skip(5).Take(15);