I know in python you can do something like myList[1:20]
but is there anything similar 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With