C# – how to compare two arrays of objects

.net-3.5arraysccomparison

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

Best Answer

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

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