Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ListOfUsers
- {
- public Guid idUser { get; set; }
- public string FIO { get; set; }
- }
- public ICollection<ListOfUsers> First { get; set; }
- public IEnumerable<Guid> Second { get; set; }
- public ICollection<ListOfUsers> Result { get; set; }
- foreach (var second in Second)
- {
- foreach (var first in First)
- {
- if (second != first.idUser)
- {
- Ressult.Add(new ListOfUsers
- {
- idUser = first.idUser,
- FIO = first.FIO
- });
- }
- }
- }
- var first = new List<ListOfUsers>
- {
- new ListOfUsers { idUser = Guid.Parse("B7AADF05-1F63-4A20-94B1-9A31F4AB4910"), FIO = "Ivan Ivanov"},
- new ListOfUsers { idUser = Guid.Parse("B7AADF05-1F63-4A20-94B1-9A31F4AB4911"), FIO = "Petr Petrov"},
- new ListOfUsers { idUser = Guid.Parse("B7AADF05-1F63-4A20-94B1-9A31F4AB4912"), FIO = "A K"},
- new ListOfUsers { idUser = Guid.Parse("B7AADF05-1F63-4A20-94B1-9A31F4AB4913"), FIO = "Sanvirtus Sanvirtus"},
- };
- var second = new List<Guid>
- {
- Guid.Parse("B7AADF05-1F63-4A20-94B1-9A31F4AB4910"),
- Guid.Parse("B7AADF05-1F63-4A20-94B1-9A31F4AB4911"),
- };
- var result = new List<ListOfUsers>();
- foreach (var element in first)
- {
- var isElementPresentInSecond = second.Any(x => x == element.idUser);
- if(isElementPresentInSecond)
- {
- continue;
- }
- else
- {
- result.Add(element);
- }
- }
- class ListOfUsersByIdEqualityCmparer : IEqualityComparer<ListOfUsers>
- {
- public bool Equals(ListOfUsers x, ListOfUsers y)
- {
- return x?.IdUser == y?.IdUser;
- }
- public int GetHashCode(ListOfUsers obj)
- {
- return obj?.IdUser.GetHashCode() ?? 0;
- }
- }
- var result = new HashSet(first, new ListOfUsersByIdEqualityCmparer());
- result.ExceptWith(second.Select(s=>new ListOfUsers(){ idUser = s }));
- var result = first.Except(second.Select(s => new ListOfUsers() { IdUser = s }), new ListOfUsersByIdEqualityCmparer());
Add Comment
Please, Sign In to add comment