fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Company
  6. {
  7. public Company(List<User> users) { this.Users = users; }
  8. public List<User> Users { get; set; }
  9. }
  10.  
  11. class User
  12. {
  13. public User(string name) { this.Name = name; }
  14. public string Name { get; set; }
  15. }
  16.  
  17. class Program
  18. {
  19. static void Main(string[] args)
  20. {
  21. List<Company> companies = new List<Company>();
  22. Company company1 = new Company(new List<User>(){ new User("first user"), new User("second user") });
  23. Company company2 = new Company(new List<User>() { new User("third user"), new User("fourth user") });
  24. companies.Add(company1);
  25. companies.Add(company2);
  26.  
  27. companies = companies
  28. .Where(company => company.Users.Any(user => user.Name.Contains("third")))
  29. .ToList();
  30.  
  31. foreach (Company company in companies) {
  32. Console.WriteLine(string.Join(", ", company.Users.Select(user => user.Name).ToArray()));
  33. }
  34. }
  35. }
Success #stdin #stdout 0.03s 38232KB
stdin
Standard input is empty
stdout
third user, fourth user