fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var people = new List<Person>
  10. {
  11. new Person { ID = 1, Name = "Fred1" },
  12. new Person { ID = 2, Name = "Fred2" },
  13. new Person { ID = 3, Name = "Fred3" },
  14. new Person { ID = 4, Name = "Fred4" },
  15. new Person { ID = 5, Name = "Fred5" },
  16. new Person { ID = 6, Name = "Fred6" },
  17. new Person { ID = 7, Name = "Fred7" },
  18. new Person { ID = 8, Name = "Fred8" },
  19. new Person { ID = 9, Name = "Fred9" },
  20. new Person { ID = 10, Name = "Fred10" }
  21. };
  22.  
  23. List<int> toRemove = new List<int> { 3, 4, 5 };
  24.  
  25. people = people.Where(p => !toRemove.Contains(p.ID)).ToList();
  26.  
  27. people.ForEach(p => Console.WriteLine("Person {0} is called {1}", p.ID, p.Name));
  28. }
  29. }
  30.  
  31. public class Person
  32. {
  33. public int ID { get; set; }
  34. public string Name { get; set; }
  35. }
Success #stdin #stdout 0.05s 24504KB
stdin
Standard input is empty
stdout
Person 1 is called Fred1
Person 2 is called Fred2
Person 6 is called Fred6
Person 7 is called Fred7
Person 8 is called Fred8
Person 9 is called Fred9
Person 10 is called Fred10