Eliminate duplicate values with LINQ UNION
There is a possible to have duplicate entries in the output list When using the LINQ ‘UNION’ operation to join two list object. There are couple of ways to overcome this issue.
The solution here we are going to discuss is with IEqualityComparer.
In this example we are going to do a union of two employee objects.
Add a class to implement IEqualityComparer as follows
class EmployeeComparer : IEqualityComparer<Employee>
{
public bool Equals(Employee e1, Employee e2)
{
return e1.Number == e2.Number;
}
public int GetHashCode(Employee e)
{
return e.Number;
}
}
public bool Equals(Employee e1, Employee e2)
{
return e1.Number == e2.Number;
}
public int GetHashCode(Employee e)
{
return e.Number;
}
}
Then just add it as the second parameter to the constructor.
var merged = employeeList1.Union(employeeList2, new EmployeeComparer());
ReplyDeleteyou can inrease your ad revneue by adding contextual ads with google ads or as an alternative to google ads just read here http://adsensealternate.blogspot.in/2015/10/Infolink-best-adsense-alternative.html and give it a
try i assure you won't regret with it
just 5 minute account set up .... noting to loose just try for 2 days