Remove last x elements from the list
c#, list
Solution
No, there isn't... But if you want you can put it in an extension method.
static class ListEx
{
public static void RemoveFrom<T>(this List<T> lst, int from)
{
lst.RemoveRange(from, lst.Count - from);
}
}
Problem
Lets say I have a `List<Car> Cars` that have n items and I want to delete the last two. The best way that I found is: `Cars.RemoveRange(Cars.Count-2, 2);` Is there better way? I searching something like this: `Cars.RemoveFrom(Cars.Count-2); //pseudocode`