Recently, I've got interested in the List.GetRange()
function. It can retrieve a sub-list from a bigger list. Usage requires two arguments:
List<T> SubList = List<T>.GetRange(10, 20) //Get 20 items, starting from index 10
But what if I wanted to take every remaining item from a specific index, with this function?
List<T> RemainingItemsFromList = MyList.GetRange(7, /*REST*/) //What can I insert into REST to make it retrieve everything?
Is there
- Any built-in
RestOfTheList
statement without doing something likeLength - Index
? - Any replacement function (that already exists)?
- Any other alternative?
or am I simply doing something wrong?
Since
List
does not provide built-in method with required functionality, your options are:1) Create extension method yourself:
2) Use LINQ: