同じタイプ (顧客) の 2 つのリストに参加する必要がある課題があります。それらには、繰り返しを避けるために必要な同様のエントリがあります。
これは私の顧客クラスです:
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>
という名前の 2 つの がcustomers1
ありcustomers2
ます。Collections メソッドを使用せずにこれら 2 つを結合する必要があります (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});
しかし、これにより、両方のリストに表示されるメンバーが得られます。しかし、繰り返しなしですべてが必要です。解決策はありますか???