You can create your own custom implementation of IEqualityComparer like the below:
Here is a Fiddle example where the last four employees from List1 should be returned: https://dotnetfiddle.net/f3sBLq
In this example, EmployeeComparer
inherits from IEqualityComparer<Employee>
where Employee is a class with the properties you listed (EmployeeID, Firstname, Lastname, Employmentstatus)
public class EmployeeComparer : IEqualityComparer<Employee>
{
public int GetHashCode(Employee co)
{
if (co == null)
{
return 0;
}
//You can use any property you want (other than EmployeeID for your purposes); the GetHashCode metho is used to generate an address to where the object is stored
return co.Employmentstatus.GetHashCode();
}
public bool Equals(Employee x1, Employee x2)
{
if (object.ReferenceEquals(x1, x2))
{
return true;
}
if (object.ReferenceEquals(x1, null) || object.ReferenceEquals(x2, null))
{
return false;
}
// Check for equality with all properties except for EmployeeID
return x1.Employmentstatus == x2.Employmentstatus && x1.Firstname == x2.Firstname && x1.Lastname == x2.Lastname;
}
}
Then you can use it like this:
var results = List2.Except(List1, new EmployeeComparer()).ToList();
Edit: Original question did not list ID
as property and requested how to exclude EmployeeID
which is what this answer and Fiddle link example are both based on.