共用方式為


HOW TO:傳回兩個序列的交集 (LINQ to SQL)

更新: November 2007

使用 Intersect 運算子可傳回兩個序列的集合交集。

範例

這個範例使用 Intersect 傳回同時有 Customers 和 Employees 居住的所有國家序列。

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

在 LINQ to SQL 中,Intersect 作業僅妥善定義於集合上。尚未定義多重集 (Multiset) 的語意 (Semantics)。

請參閱

參考

標準查詢運算子轉譯 (LINQ to SQL)

其他資源

查詢範例 (LINQ to SQL)