I have an assignment where I have to join two lists of the same type (Customer). They have similar entries which I have to avoid repetitions.
This is my customer class:
class Customer
{
private String _fName, _lName;
private int _age, _cusIndex;
private float _expenses;
public Customer(String fName, String lName, int age, float expenses, int cusIndex)
{
this._fName = fName;
this._lName = lName;
this._age = age;
this._expenses = expenses;
this._cusIndex = cusIndex;
}
}
So I have two List<Customer>
s named customers1
and customers2
. I need to join these two without using Collections methods (like customer1.Union(customer2).ToList();
But using Linq queries.
Here's the Linq query I wrote:
var joined = (from c1 in customers1
join c2 in customers2
on c1.CusIndex equals c2.CusIndex
select new {c1, c2});
But this gives me the member who appear on both of the lists. But I need all, without repetition. Are there any solution ???