I'm sure that my question is similar to many questions asked on StackOverflow. But I think that my problem is a little bit different from the questions asked here.
What I need exactly is to compare two lists of objects with only Id and with the ignorance of order :
List 1 of Person { Id Name }
List 2 of Person { Id Name }
Suppose that I have these two lists:
List 1 { 1 , John } , {2 , Mike } , {3 , Justin }
List 2 { 2 , Mike } , {1 , John } , {3 , Justin }
In this case, the result returned should be true
because the two lists are equals ignoring the order.
In another case:
List 1 { 1 , John } , {2 , Mike } , {4 , Justin }
List 2 { 2 , Mike } , {1 , John } , {3 , Justin }
This should returns false
.
I've tried Find
, FindAll
, Except
but any of them worked for me.
this is the last solution that I've tried:
foreach(PersonModel d in PersonsList1) {
var Test = PersonsList2.All(x => x.Id== d.Id);
}
How can I get this works?
Note: there is no occurrence in the two lists
Thanks.