There are 2 arrays, the first array of the following type:
public class ListOfUsers { public Guid idUser { get; set; } public string FIO { get; set; } } The second array is an IEnumerable<Guid> .
public ICollection<ListOfUsers> First { get; set; } public IEnumerable<Guid> Second { get; set; } public ICollection<ListOfUsers> Result { get; set; } The First array contains the unique identifier of the user and his full name. The Second array contains only unique user IDs. How do I compare these arrays as follows:
If the element of the array First is in the array Second, then skip it. If not, then add this element to the Result array and, at the end, sort the array of results by the FIO field?
I tried to do this in the following way, but for me everything is duplicated as many times as there are elements in the Second array:
foreach (var second in Second) { foreach (var first in First) { if (second != first.idUser) { Ressult.Add(new ListOfUsers { idUser = first.idUser, FIO = first.FIO }); } } } 
ExceptWithmethodExceptWithOnly the type must be the same - GrundyContainsmethod instead. Due to the fact that HashSet stores hashcodes and searches them, then searching them in computing resources will cost less. - adrug