HOW TO:從序列去除重複的項目 (LINQ to SQL)
更新: November 2007
使用 Distinct 運算子去除序列中重複的項目。
範例
下列範例使用 Distinct 來選取一連串具有客戶的唯一城市。
Dim cityQuery = _
(From cust In db.Customers _
Select cust.City).Distinct()
For Each cityString In cityQuery
Console.WriteLine(cityString)
Next
IQueryable<String> cityQuery =
(from cust in db.Customers
select cust.City).Distinct();
foreach (String cityString in cityQuery)
{
Console.WriteLine(cityString);
}