更新时间:2023-02-14 10:21:34
对集合进行操作的三个有用的Linq概念.给定集合c
和集合e
:
Three useful Linq concepts operating on sets. Given set c
and set e
:
Concat为您提供c
或e
中的所有内容:
Concat gives you everything in c
or e
:
(From c In db.Customers Select c.Phone).Concat( _
From c In db.Customers Select c.Fax).Concat( _
From e In db.Employees Select e.HomePhone)
(From c In db.Customers _
Select Name = c.CompanyName, Phone = c.Phone).Concat(From e In db.Employees _
Select Name = e.FirstName & " " & e.LastName, Phone = e.HomePhone)
联盟还为您提供c
和e
中的所有内容,但会删除所有重复项:
Union also gives you everything in c
and e
, but removes any duplicates:
(From c In db.Customers _
Select c.Country).Union(From e In db.Employees _
Select e.Country)
除了在c
中为您提供的所有内容以外,在e
中没有其他内容:
Except gives you everything in c
that is not in e
:
(From c In db.Customers _
Select c.Country).Except(From e In db.Employees Select e.Country)