我有一个任务,我必须加入两个相同类型的列表(客户)。他们有类似的条目,我必须避免重复。
这是我的客户类:
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;
}
}
所以我有两个List<Customer>
名为customers1
and customers2
。我需要在不使用 Collections 方法的情况下加入这两个(例如customer1.Union(customer2).ToList();
但使用 Linq 查询。
这是我写的Linq 查询:
var joined = (from c1 in customers1
join c2 in customers2
on c1.CusIndex equals c2.CusIndex
select new {c1, c2});
但这给了我出现在两个列表中的成员。但我需要所有,没有重复。有什么解决办法???