How do I truncate a list in C#?
问题 I know in python you can do something like myList[1:20] but is there anything similar in C#? 回答1: var itemsOneThroughTwenty = myList.Take(20); var itemsFiveThroughTwenty = myList.Skip(5).Take(15); 回答2: 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) 回答3: This might be helpful for efficiency, if you really want to truncate the list, not make a