Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. IEnumberable<Car> list
  2.  
  3. list.RemoveWhere(r=>r.Year > 2000)
  4.  
  5. list = list.Where(r=>r.Year<=2000)
  6.  
  7. public static IEnumerable<T> RemoveWhere<T>(this IEnumerable<T> query, Predicate<T> predicate)
  8. {
  9. return query.Where(e => !predicate(e));
  10. }
  11.  
  12. MyList.RemoveAll( p => p.MyProperty == MyValue );
  13.  
  14. list = list.Where(car => car.Year <= 2000);
  15.  
  16. public static class CollectionExtensions {
  17. public static ICollection<T> RemoveWhere<T>(this ICollection<T> collection, Func<T, bool> predicate) {
  18. List<T> toRemove = collection.Where(item => predicate(item)).ToList();
  19. toRemove.ForEach(item => collection.Remove(item));
  20. return collection;
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement