2 つのシーケンスの積集合の取得

2 つのシーケンスの積集合を返すには、Intersect 演算子を使用します。

この例では、Intersect を使用して、CustomersEmployees の両方が居住しているすべての国や地域のシーケンスが返されます。

var infoQuery =
    (from cust in db.Customers
    select cust.Country)
    .Intersect
        (from emp in db.Employees
        select emp.Country)
;
Dim infoQuery = _
    (From cust In db.Customers _
     Select cust.Country) _
    .Intersect _
        (From emp In db.Employees _
         Select emp.Country)

LINQ to SQL では、Intersect 演算は集合でのみ適切に定義されます。 マルチセットのセマンティクスは未定義です。

関連項目