Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to compare two arrays of objects

i have an object called Person. It has properties First, Last, Age, etc . . .

I have two arrays of Person objects.

I want to have some function to take two arrays

Person[] firstlist =  . .
Person[] secondList =  . . 

and have it spit out two new arrays

Person[] peopleinFirstListandNotSecond
Person[] peopleinSecondListandNotFirst

Since these are not string arrays, i would want to do a compare on first and last name and age to determine if its the same person

like image 985
leora Avatar asked Oct 30 '25 03:10

leora


1 Answers

Here is a linq function (IEnumerable<T>.Except(...)) that will do what you need.

http://msdn.microsoft.com/en-us/library/bb336390.aspx

like image 94
Daniel A. White Avatar answered Oct 31 '25 17:10

Daniel A. White



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!