Share via


傳回兩個序列的集合交集

使用 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 作業只會在集合上適當地定義。 尚未定義多重集 (Multiset) 的語意 (Semantics)。

另請參閱