c# - Remove last x elements from the list -
lets have list<car> cars
have n items , want delete last two. best way found is:
cars.removerange(cars.count-2, 2);
is there better way? searching this:
cars.removefrom(cars.count-2); //pseudocode
no, there isn't... if want can put in extension method.
static class listex { public static void removefrom<t>(this list<t> lst, int from) { lst.removerange(from, lst.count - from); } }
Comments
Post a Comment