CollectionExtensions.cs 506 B

1234567891011121314151617181920212223
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using JetBrains.Annotations;
  5. namespace IwbYue.Zero.Zero
  6. {
  7. public static class CollectionExtensions
  8. {
  9. public static IList<T> RemoveAll<T>([NotNull] this ICollection<T> source, Func<T, bool> predicate)
  10. {
  11. var items = source.Where(predicate).ToList();
  12. foreach (var item in items)
  13. {
  14. source.Remove(item);
  15. }
  16. return items;
  17. }
  18. }
  19. }