Share via


傳回兩個序列之間的集合差異

使用 Except 運算子傳回兩個序列之間的集合差異。

範例

此範例使用 Except 傳回有 Customers 居住但無 Employees 居住的所有國家/地區序列。

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

在 LINQ to SQL 中,Except 作業只會在集合上適當地定義。 尚未定義多重集 (Multiset) 的語意 (Semantics)。

另請參閱