Guest User

Untitled

a guest
Jul 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. public class ListOfUsers
  2. {
  3. public Guid idUser { get; set; }
  4. public string FIO { get; set; }
  5. }
  6.  
  7. public ICollection<ListOfUsers> First { get; set; }
  8. public IEnumerable<Guid> Second { get; set; }
  9. public ICollection<ListOfUsers> Result { get; set; }
  10.  
  11. foreach (var second in Second)
  12. {
  13. foreach (var first in First)
  14. {
  15. if (second != first.idUser)
  16. {
  17. Ressult.Add(new ListOfUsers
  18. {
  19. idUser = first.idUser,
  20. FIO = first.FIO
  21. });
  22. }
  23. }
  24. }
  25.  
  26. var first = new List<ListOfUsers>
  27. {
  28. new ListOfUsers { idUser = Guid.Parse("B7AADF05-1F63-4A20-94B1-9A31F4AB4910"), FIO = "Ivan Ivanov"},
  29. new ListOfUsers { idUser = Guid.Parse("B7AADF05-1F63-4A20-94B1-9A31F4AB4911"), FIO = "Petr Petrov"},
  30. new ListOfUsers { idUser = Guid.Parse("B7AADF05-1F63-4A20-94B1-9A31F4AB4912"), FIO = "A K"},
  31. new ListOfUsers { idUser = Guid.Parse("B7AADF05-1F63-4A20-94B1-9A31F4AB4913"), FIO = "Sanvirtus Sanvirtus"},
  32. };
  33.  
  34. var second = new List<Guid>
  35. {
  36. Guid.Parse("B7AADF05-1F63-4A20-94B1-9A31F4AB4910"),
  37. Guid.Parse("B7AADF05-1F63-4A20-94B1-9A31F4AB4911"),
  38. };
  39.  
  40. var result = new List<ListOfUsers>();
  41.  
  42. foreach (var element in first)
  43. {
  44. var isElementPresentInSecond = second.Any(x => x == element.idUser);
  45.  
  46. if(isElementPresentInSecond)
  47. {
  48. continue;
  49. }
  50. else
  51. {
  52. result.Add(element);
  53. }
  54. }
  55.  
  56. class ListOfUsersByIdEqualityCmparer : IEqualityComparer<ListOfUsers>
  57. {
  58. public bool Equals(ListOfUsers x, ListOfUsers y)
  59. {
  60. return x?.IdUser == y?.IdUser;
  61. }
  62.  
  63. public int GetHashCode(ListOfUsers obj)
  64. {
  65. return obj?.IdUser.GetHashCode() ?? 0;
  66. }
  67. }
  68.  
  69. var result = new HashSet(first, new ListOfUsersByIdEqualityCmparer());
  70. result.ExceptWith(second.Select(s=>new ListOfUsers(){ idUser = s }));
  71.  
  72. var result = first.Except(second.Select(s => new ListOfUsers() { IdUser = s }), new ListOfUsersByIdEqualityCmparer());
Add Comment
Please, Sign In to add comment